﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using MyLib;

namespace ImportSubscriber
{
    /// <summary>
    /// DBCommands
    /// <example>This example shows how to use DBCommands:
    /// <code>
    /// <newpara/>
    /// DBCommands db = new DBCommands(connection_string);
    /// <newpara/>
    /// </code>
    /// </example>
    /// </summary>
	public class DBCommands : MyLib.DBCommandsBase
	{
		public DBCommands(string connectString) : base(connectString) { }

        /// <summary>
        /// DBCommands
        /// <example>This example shows how to use transaction:
        /// <code>
        /// <newpara/>
        /// try
        /// {
        ///    Common.db.ExceptionMode = true;
        ///    Common.db.BeginTransaction();
        ///    Common.db.ExecSqlCmd(@"update t1 set name = @name where id=@id", name, id1);
        ///    Common.db.ExecSqlCmd(......);
        ///    Common.db.Commit();
        /// }
        /// catch (Exception ex)
        /// {
        ///    Common.db.Rollback();
        ///    MessageBox.Show(ex.ExceptionInfo());
        /// }
        /// finally
        /// {
        ///    Common.db.ExceptionMode = false;
        /// }
        /// <newpara/>
        /// </code>
        /// </example>
        /// </summary>

		#region AttachmentsInChangeRequest
		//**********************************************************
		//  AttachmentsInChangeRequest
		//**********************************************************
        CMD_AttachmentsInChangeRequest m_AttachmentsInChangeRequest = null;
        public CMD_AttachmentsInChangeRequest AttachmentsInChangeRequest
        {
            get
            {
				if (m_AttachmentsInChangeRequest == null)
					m_AttachmentsInChangeRequest = new CMD_AttachmentsInChangeRequest(this);
				return m_AttachmentsInChangeRequest;
			}
        }

		[Serializable]
		public class TBL_AttachmentsInChangeRequest
		{
			public int ID { get; set; }
			public int ChangeRequestID { get; set; }
			public int ChangeRequestRole { get; set; }
			public string AttachmentName { get; set; }
			public byte[] AttachmentDetails { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public string AttachmentContentType { get; set; }

			public TBL_AttachmentsInChangeRequest()
			{
				this.ID = 0;
				this.ChangeRequestID = 0;
				this.ChangeRequestRole = 0;
				this.AttachmentName = "";
				this.AttachmentDetails = new byte[0];
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.AttachmentContentType = "";
			}

			public TBL_AttachmentsInChangeRequest(int ID, int ChangeRequestID, int ChangeRequestRole, string AttachmentName, byte[] AttachmentDetails, int CreatedBy, DateTime CreatedDatetime, string AttachmentContentType)
			{
				this.ID = ID;
				this.ChangeRequestID = ChangeRequestID;
				this.ChangeRequestRole = ChangeRequestRole;
				this.AttachmentName = AttachmentName;
				this.AttachmentDetails = AttachmentDetails;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.AttachmentContentType = AttachmentContentType;
			}

			public void CopyTo(ref TBL_AttachmentsInChangeRequest to)
			{
				to.ID = this.ID;
				to.ChangeRequestID = this.ChangeRequestID;
				to.ChangeRequestRole = this.ChangeRequestRole;
				to.AttachmentName = this.AttachmentName;
				to.AttachmentDetails = this.AttachmentDetails;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.AttachmentContentType = this.AttachmentContentType;
			}

			public bool IsSame(TBL_AttachmentsInChangeRequest x)
			{
				return(
					this.ID == x.ID &&
					this.ChangeRequestID == x.ChangeRequestID &&
					this.ChangeRequestRole == x.ChangeRequestRole &&
					this.AttachmentName == x.AttachmentName &&
					this.AttachmentDetails == x.AttachmentDetails &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.AttachmentContentType == x.AttachmentContentType
				);
			}

			public static TBL_AttachmentsInChangeRequest ReadRow(DataRow row)
			{
				TBL_AttachmentsInChangeRequest record = new TBL_AttachmentsInChangeRequest();
				record.ID = get_int_value(row["ID"]);
				record.ChangeRequestID = get_int_value(row["ChangeRequestID"]);
				record.ChangeRequestRole = get_int_value(row["ChangeRequestRole"]);
				record.AttachmentName = get_string_value(row["AttachmentName"]);
				record.AttachmentDetails = get_bytes_value(row["AttachmentDetails"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.AttachmentContentType = get_string_value(row["AttachmentContentType"]);
				return record;
			}

			public static List<TBL_AttachmentsInChangeRequest> ReadTable(DataTable dt)
			{
				List<TBL_AttachmentsInChangeRequest> records = new List<TBL_AttachmentsInChangeRequest>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_AttachmentsInChangeRequest
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_AttachmentsInChangeRequest(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ChangeRequestID, ChangeRequestRole, AttachmentName, AttachmentDetails, CreatedBy, CreatedDatetime, AttachmentContentType
					from AttachmentsInChangeRequest
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "AttachmentsInChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "AttachmentsInChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_AttachmentsInChangeRequest data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_AttachmentsInChangeRequest.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AttachmentsInChangeRequest.ID, AttachmentsInChangeRequest.ChangeRequestID, AttachmentsInChangeRequest.ChangeRequestRole, AttachmentsInChangeRequest.AttachmentName, AttachmentsInChangeRequest.AttachmentDetails, AttachmentsInChangeRequest.CreatedBy, AttachmentsInChangeRequest.CreatedDatetime, AttachmentsInChangeRequest.AttachmentContentType
					from AttachmentsInChangeRequest
					where AttachmentsInChangeRequest.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ChangeRequestID, ChangeRequestRole, AttachmentName, AttachmentDetails, CreatedBy, CreatedDatetime, AttachmentContentType
					from AttachmentsInChangeRequest
					", ref dt);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AttachmentsInChangeRequest.ID, AttachmentsInChangeRequest.ChangeRequestID, AttachmentsInChangeRequest.ChangeRequestRole, AttachmentsInChangeRequest.AttachmentName, AttachmentsInChangeRequest.AttachmentDetails, AttachmentsInChangeRequest.CreatedBy, AttachmentsInChangeRequest.CreatedDatetime, AttachmentsInChangeRequest.AttachmentContentType
					from AttachmentsInChangeRequest
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AttachmentsInChangeRequest.ID, AttachmentsInChangeRequest.ChangeRequestID, AttachmentsInChangeRequest.ChangeRequestRole, AttachmentsInChangeRequest.AttachmentName, AttachmentsInChangeRequest.AttachmentDetails, AttachmentsInChangeRequest.CreatedBy, AttachmentsInChangeRequest.CreatedDatetime, AttachmentsInChangeRequest.AttachmentContentType
					from AttachmentsInChangeRequest
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ChangeRequestID,
				int ChangeRequestRole,
				string AttachmentName,
				byte[] AttachmentDetails,
				int CreatedBy,
				DateTime CreatedDatetime,
				string AttachmentContentType
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into AttachmentsInChangeRequest(
						ChangeRequestID,
						ChangeRequestRole,
						AttachmentName,
						AttachmentDetails,
						CreatedBy,
						CreatedDatetime,
						AttachmentContentType
						)
					values(
						@ChangeRequestID,
						@ChangeRequestRole,
						@AttachmentName,
						@AttachmentDetails,
						@CreatedBy,
						@CreatedDatetime,
						@AttachmentContentType
						)
					", ChangeRequestID, ChangeRequestRole, AttachmentName, AttachmentDetails, CreatedBy, CreatedDatetime, AttachmentContentType);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int ChangeRequestID,
				int ChangeRequestRole,
				string AttachmentName,
				byte[] AttachmentDetails,
				int CreatedBy,
				DateTime CreatedDatetime,
				string AttachmentContentType
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from AttachmentsInChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "AttachmentsInChangeRequest.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "AttachmentsInChangeRequest.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update AttachmentsInChangeRequest
					set
						ChangeRequestID = @ChangeRequestID,
						ChangeRequestRole = @ChangeRequestRole,
						AttachmentName = @AttachmentName,
						AttachmentDetails = @AttachmentDetails,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						AttachmentContentType = @AttachmentContentType
					where ID=@ID
					",
					ChangeRequestID,
					ChangeRequestRole,
					AttachmentName,
					AttachmentDetails,
					CreatedBy,
					CreatedDatetime,
					AttachmentContentType,
					ID
				);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from AttachmentsInChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "AttachmentsInChangeRequest.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "AttachmentsInChangeRequest.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from AttachmentsInChangeRequest where ID=@ID", ID);
                if (!_ok) m_db.LastError = "AttachmentsInChangeRequest.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region AttachmentsInNotice
		//**********************************************************
		//  AttachmentsInNotice
		//**********************************************************
        CMD_AttachmentsInNotice m_AttachmentsInNotice = null;
        public CMD_AttachmentsInNotice AttachmentsInNotice
        {
            get
            {
				if (m_AttachmentsInNotice == null)
					m_AttachmentsInNotice = new CMD_AttachmentsInNotice(this);
				return m_AttachmentsInNotice;
			}
        }

		[Serializable]
		public class TBL_AttachmentsInNotice
		{
			public int ID { get; set; }
			public int NoticeID { get; set; }
			public byte[] AttachmentDetails { get; set; }
			public string AttachmentName { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDatetime { get; set; }
			public string AttachmentContentType { get; set; }

			public TBL_AttachmentsInNotice()
			{
				this.ID = 0;
				this.NoticeID = 0;
				this.AttachmentDetails = new byte[0];
				this.AttachmentName = "";
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.AttachmentContentType = "";
			}

			public TBL_AttachmentsInNotice(int ID, int NoticeID, byte[] AttachmentDetails, string AttachmentName, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDatetime, string AttachmentContentType)
			{
				this.ID = ID;
				this.NoticeID = NoticeID;
				this.AttachmentDetails = AttachmentDetails;
				this.AttachmentName = AttachmentName;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDatetime = ModifiedDatetime;
				this.AttachmentContentType = AttachmentContentType;
			}

			public void CopyTo(ref TBL_AttachmentsInNotice to)
			{
				to.ID = this.ID;
				to.NoticeID = this.NoticeID;
				to.AttachmentDetails = this.AttachmentDetails;
				to.AttachmentName = this.AttachmentName;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDatetime = this.ModifiedDatetime;
				to.AttachmentContentType = this.AttachmentContentType;
			}

			public bool IsSame(TBL_AttachmentsInNotice x)
			{
				return(
					this.ID == x.ID &&
					this.NoticeID == x.NoticeID &&
					this.AttachmentDetails == x.AttachmentDetails &&
					this.AttachmentName == x.AttachmentName &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDatetime == x.ModifiedDatetime &&
					this.AttachmentContentType == x.AttachmentContentType
				);
			}

			public static TBL_AttachmentsInNotice ReadRow(DataRow row)
			{
				TBL_AttachmentsInNotice record = new TBL_AttachmentsInNotice();
				record.ID = get_int_value(row["ID"]);
				record.NoticeID = get_int_value(row["NoticeID"]);
				record.AttachmentDetails = get_bytes_value(row["AttachmentDetails"]);
				record.AttachmentName = get_string_value(row["AttachmentName"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDatetime = get_DateTime_value(row["ModifiedDatetime"]);
				record.AttachmentContentType = get_string_value(row["AttachmentContentType"]);
				return record;
			}

			public static List<TBL_AttachmentsInNotice> ReadTable(DataTable dt)
			{
				List<TBL_AttachmentsInNotice> records = new List<TBL_AttachmentsInNotice>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_AttachmentsInNotice
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_AttachmentsInNotice(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, NoticeID, AttachmentDetails, AttachmentName, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime, AttachmentContentType
					from AttachmentsInNotice
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "AttachmentsInNotice.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "AttachmentsInNotice.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_AttachmentsInNotice data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_AttachmentsInNotice.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AttachmentsInNotice.ID, AttachmentsInNotice.NoticeID, AttachmentsInNotice.AttachmentDetails, AttachmentsInNotice.AttachmentName, AttachmentsInNotice.CreatedBy, AttachmentsInNotice.CreatedDatetime, AttachmentsInNotice.ModifiedBy, AttachmentsInNotice.ModifiedDatetime, AttachmentsInNotice.AttachmentContentType
					from AttachmentsInNotice
					where AttachmentsInNotice.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, NoticeID, AttachmentDetails, AttachmentName, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime, AttachmentContentType
					from AttachmentsInNotice
					", ref dt);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "AttachmentsInNotice.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AttachmentsInNotice.ID, AttachmentsInNotice.NoticeID, AttachmentsInNotice.AttachmentDetails, AttachmentsInNotice.AttachmentName, AttachmentsInNotice.CreatedBy, AttachmentsInNotice.CreatedDatetime, AttachmentsInNotice.ModifiedBy, AttachmentsInNotice.ModifiedDatetime, AttachmentsInNotice.AttachmentContentType
					from AttachmentsInNotice
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AttachmentsInNotice.ID, AttachmentsInNotice.NoticeID, AttachmentsInNotice.AttachmentDetails, AttachmentsInNotice.AttachmentName, AttachmentsInNotice.CreatedBy, AttachmentsInNotice.CreatedDatetime, AttachmentsInNotice.ModifiedBy, AttachmentsInNotice.ModifiedDatetime, AttachmentsInNotice.AttachmentContentType
					from AttachmentsInNotice
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int NoticeID,
				byte[] AttachmentDetails,
				string AttachmentName,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime,
				string AttachmentContentType
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into AttachmentsInNotice(
						NoticeID,
						AttachmentDetails,
						AttachmentName,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDatetime,
						AttachmentContentType
						)
					values(
						@NoticeID,
						@AttachmentDetails,
						@AttachmentName,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDatetime,
						@AttachmentContentType
						)
					", NoticeID, AttachmentDetails, AttachmentName, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime, AttachmentContentType);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int NoticeID,
				byte[] AttachmentDetails,
				string AttachmentName,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime,
				string AttachmentContentType
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from AttachmentsInNotice where ID=@ID", ref count, ID))
				{
					m_db.LastError = "AttachmentsInNotice.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "AttachmentsInNotice.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update AttachmentsInNotice
					set
						NoticeID = @NoticeID,
						AttachmentDetails = @AttachmentDetails,
						AttachmentName = @AttachmentName,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDatetime = @ModifiedDatetime,
						AttachmentContentType = @AttachmentContentType
					where ID=@ID
					",
					NoticeID,
					AttachmentDetails,
					AttachmentName,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDatetime,
					AttachmentContentType,
					ID
				);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from AttachmentsInNotice where ID=@ID", ref count, ID))
				{
					m_db.LastError = "AttachmentsInNotice.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "AttachmentsInNotice.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from AttachmentsInNotice where ID=@ID", ID);
                if (!_ok) m_db.LastError = "AttachmentsInNotice.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region AuditTrail
		//**********************************************************
		//  AuditTrail
		//**********************************************************
        CMD_AuditTrail m_AuditTrail = null;
        public CMD_AuditTrail AuditTrail
        {
            get
            {
				if (m_AuditTrail == null)
					m_AuditTrail = new CMD_AuditTrail(this);
				return m_AuditTrail;
			}
        }

		[Serializable]
		public class TBL_AuditTrail
		{
			public int Id { get; set; }
			public DateTime DateTime { get; set; }
			public string Script { get; set; }
			public string User { get; set; }
			public string Action { get; set; }
			public string Table { get; set; }
			public string Field { get; set; }
			public string KeyValue { get; set; }
			public string OldValue { get; set; }
			public string NewValue { get; set; }

			public TBL_AuditTrail()
			{
				this.Id = 0;
				this.DateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.Script = "";
				this.User = "";
				this.Action = "";
				this.Table = "";
				this.Field = "";
				this.KeyValue = "";
				this.OldValue = "";
				this.NewValue = "";
			}

			public TBL_AuditTrail(int Id, DateTime DateTime, string Script, string User, string Action, string Table, string Field, string KeyValue, string OldValue, string NewValue)
			{
				this.Id = Id;
				this.DateTime = DateTime;
				this.Script = Script;
				this.User = User;
				this.Action = Action;
				this.Table = Table;
				this.Field = Field;
				this.KeyValue = KeyValue;
				this.OldValue = OldValue;
				this.NewValue = NewValue;
			}

			public void CopyTo(ref TBL_AuditTrail to)
			{
				to.Id = this.Id;
				to.DateTime = this.DateTime;
				to.Script = this.Script;
				to.User = this.User;
				to.Action = this.Action;
				to.Table = this.Table;
				to.Field = this.Field;
				to.KeyValue = this.KeyValue;
				to.OldValue = this.OldValue;
				to.NewValue = this.NewValue;
			}

			public bool IsSame(TBL_AuditTrail x)
			{
				return(
					this.Id == x.Id &&
					this.DateTime == x.DateTime &&
					this.Script == x.Script &&
					this.User == x.User &&
					this.Action == x.Action &&
					this.Table == x.Table &&
					this.Field == x.Field &&
					this.KeyValue == x.KeyValue &&
					this.OldValue == x.OldValue &&
					this.NewValue == x.NewValue
				);
			}

			public static TBL_AuditTrail ReadRow(DataRow row)
			{
				TBL_AuditTrail record = new TBL_AuditTrail();
				record.Id = get_int_value(row["Id"]);
				record.DateTime = get_DateTime_value(row["DateTime"]);
				record.Script = get_string_value(row["Script"]);
				record.User = get_string_value(row["User"]);
				record.Action = get_string_value(row["Action"]);
				record.Table = get_string_value(row["Table"]);
				record.Field = get_string_value(row["Field"]);
				record.KeyValue = get_string_value(row["KeyValue"]);
				record.OldValue = get_string_value(row["OldValue"]);
				record.NewValue = get_string_value(row["NewValue"]);
				return record;
			}

			public static List<TBL_AuditTrail> ReadTable(DataTable dt)
			{
				List<TBL_AuditTrail> records = new List<TBL_AuditTrail>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_AuditTrail
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_AuditTrail(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select Id, DateTime, Script, User, Action, Table, Field, KeyValue, OldValue, NewValue
					from AuditTrail
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "AuditTrail.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int Id,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where Id=@Id"
					, Id))
                {
                    m_db.LastError = "AuditTrail.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int Id,
				ref TBL_AuditTrail data
			)
			{
                DataTable dt = null;
				if (!select(
				        Id,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_AuditTrail.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int Id,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AuditTrail.Id, AuditTrail.DateTime, AuditTrail.Script, AuditTrail.User, AuditTrail.Action, AuditTrail.Table, AuditTrail.Field, AuditTrail.KeyValue, AuditTrail.OldValue, AuditTrail.NewValue
					from AuditTrail
					where AuditTrail.Id=@Id
					", ref dt, Id);
                if (!_ok) m_db.LastError = "AuditTrail.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Id, DateTime, Script, User, Action, Table, Field, KeyValue, OldValue, NewValue
					from AuditTrail
					", ref dt);
                if (!_ok) m_db.LastError = "AuditTrail.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "AuditTrail.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AuditTrail.Id, AuditTrail.DateTime, AuditTrail.Script, AuditTrail.User, AuditTrail.Action, AuditTrail.Table, AuditTrail.Field, AuditTrail.KeyValue, AuditTrail.OldValue, AuditTrail.NewValue
					from AuditTrail
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "AuditTrail.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AuditTrail.Id, AuditTrail.DateTime, AuditTrail.Script, AuditTrail.User, AuditTrail.Action, AuditTrail.Table, AuditTrail.Field, AuditTrail.KeyValue, AuditTrail.OldValue, AuditTrail.NewValue
					from AuditTrail
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "AuditTrail.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				DateTime DateTime,
				string Script,
				string User,
				string Action,
				string Table,
				string Field,
				string KeyValue,
				string OldValue,
				string NewValue
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into AuditTrail(
						DateTime,
						Script,
						User,
						Action,
						Table,
						Field,
						KeyValue,
						OldValue,
						NewValue
						)
					values(
						@DateTime,
						@Script,
						@User,
						@Action,
						@Table,
						@Field,
						@KeyValue,
						@OldValue,
						@NewValue
						)
					", DateTime, Script, User, Action, Table, Field, KeyValue, OldValue, NewValue);
                if (!_ok) m_db.LastError = "AuditTrail.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int Id,
				DateTime DateTime,
				string Script,
				string User,
				string Action,
				string Table,
				string Field,
				string KeyValue,
				string OldValue,
				string NewValue
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from AuditTrail where Id=@Id", ref count, Id))
				{
					m_db.LastError = "AuditTrail.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "AuditTrail.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update AuditTrail
					set
						DateTime = @DateTime,
						Script = @Script,
						User = @User,
						Action = @Action,
						Table = @Table,
						Field = @Field,
						KeyValue = @KeyValue,
						OldValue = @OldValue,
						NewValue = @NewValue
					where Id=@Id
					",
					DateTime,
					Script,
					User,
					Action,
					Table,
					Field,
					KeyValue,
					OldValue,
					NewValue,
					Id
				);
                if (!_ok) m_db.LastError = "AuditTrail.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int Id
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from AuditTrail where Id=@Id", ref count, Id))
				{
					m_db.LastError = "AuditTrail.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "AuditTrail.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from AuditTrail where Id=@Id", Id);
                if (!_ok) m_db.LastError = "AuditTrail.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillConfig
		//**********************************************************
		//  BillConfig
		//**********************************************************
        CMD_BillConfig m_BillConfig = null;
        public CMD_BillConfig BillConfig
        {
            get
            {
				if (m_BillConfig == null)
					m_BillConfig = new CMD_BillConfig(this);
				return m_BillConfig;
			}
        }

		[Serializable]
		public class TBL_BillConfig
		{
			public int ID { get; set; }
			public int EmailOnReleased { get; set; }
			public int EmailOnUnreleased { get; set; }
			public string ReleaseEmailSubject { get; set; }
			public string ReleaseEmailBody { get; set; }
			public string TaxCode { get; set; }
			public string ReleaseEmailCc { get; set; }
			public string ReleaseEmailBcc { get; set; }

			public TBL_BillConfig()
			{
				this.ID = 0;
				this.EmailOnReleased = 0;
				this.EmailOnUnreleased = 0;
				this.ReleaseEmailSubject = "";
				this.ReleaseEmailBody = "";
				this.TaxCode = "";
				this.ReleaseEmailCc = "";
				this.ReleaseEmailBcc = "";
			}

			public TBL_BillConfig(int ID, int EmailOnReleased, int EmailOnUnreleased, string ReleaseEmailSubject, string ReleaseEmailBody, string TaxCode, string ReleaseEmailCc, string ReleaseEmailBcc)
			{
				this.ID = ID;
				this.EmailOnReleased = EmailOnReleased;
				this.EmailOnUnreleased = EmailOnUnreleased;
				this.ReleaseEmailSubject = ReleaseEmailSubject;
				this.ReleaseEmailBody = ReleaseEmailBody;
				this.TaxCode = TaxCode;
				this.ReleaseEmailCc = ReleaseEmailCc;
				this.ReleaseEmailBcc = ReleaseEmailBcc;
			}

			public void CopyTo(ref TBL_BillConfig to)
			{
				to.ID = this.ID;
				to.EmailOnReleased = this.EmailOnReleased;
				to.EmailOnUnreleased = this.EmailOnUnreleased;
				to.ReleaseEmailSubject = this.ReleaseEmailSubject;
				to.ReleaseEmailBody = this.ReleaseEmailBody;
				to.TaxCode = this.TaxCode;
				to.ReleaseEmailCc = this.ReleaseEmailCc;
				to.ReleaseEmailBcc = this.ReleaseEmailBcc;
			}

			public bool IsSame(TBL_BillConfig x)
			{
				return(
					this.ID == x.ID &&
					this.EmailOnReleased == x.EmailOnReleased &&
					this.EmailOnUnreleased == x.EmailOnUnreleased &&
					this.ReleaseEmailSubject == x.ReleaseEmailSubject &&
					this.ReleaseEmailBody == x.ReleaseEmailBody &&
					this.TaxCode == x.TaxCode &&
					this.ReleaseEmailCc == x.ReleaseEmailCc &&
					this.ReleaseEmailBcc == x.ReleaseEmailBcc
				);
			}

			public static TBL_BillConfig ReadRow(DataRow row)
			{
				TBL_BillConfig record = new TBL_BillConfig();
				record.ID = get_int_value(row["ID"]);
				record.EmailOnReleased = get_int_value(row["EmailOnReleased"]);
				record.EmailOnUnreleased = get_int_value(row["EmailOnUnreleased"]);
				record.ReleaseEmailSubject = get_string_value(row["ReleaseEmailSubject"]);
				record.ReleaseEmailBody = get_string_value(row["ReleaseEmailBody"]);
				record.TaxCode = get_string_value(row["TaxCode"]);
				record.ReleaseEmailCc = get_string_value(row["ReleaseEmailCc"]);
				record.ReleaseEmailBcc = get_string_value(row["ReleaseEmailBcc"]);
				return record;
			}

			public static List<TBL_BillConfig> ReadTable(DataTable dt)
			{
				List<TBL_BillConfig> records = new List<TBL_BillConfig>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillConfig
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillConfig(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, EmailOnReleased, EmailOnUnreleased, ReleaseEmailSubject, ReleaseEmailBody, TaxCode, ReleaseEmailCc, ReleaseEmailBcc
					from BillConfig
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillConfig.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillConfig.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillConfig data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillConfig.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillConfig.ID, BillConfig.EmailOnReleased, BillConfig.EmailOnUnreleased, BillConfig.ReleaseEmailSubject, BillConfig.ReleaseEmailBody, BillConfig.TaxCode, BillConfig.ReleaseEmailCc, BillConfig.ReleaseEmailBcc
					from BillConfig
					where BillConfig.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillConfig.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, EmailOnReleased, EmailOnUnreleased, ReleaseEmailSubject, ReleaseEmailBody, TaxCode, ReleaseEmailCc, ReleaseEmailBcc
					from BillConfig
					", ref dt);
                if (!_ok) m_db.LastError = "BillConfig.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillConfig.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillConfig.ID, BillConfig.EmailOnReleased, BillConfig.EmailOnUnreleased, BillConfig.ReleaseEmailSubject, BillConfig.ReleaseEmailBody, BillConfig.TaxCode, BillConfig.ReleaseEmailCc, BillConfig.ReleaseEmailBcc
					from BillConfig
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillConfig.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillConfig.ID, BillConfig.EmailOnReleased, BillConfig.EmailOnUnreleased, BillConfig.ReleaseEmailSubject, BillConfig.ReleaseEmailBody, BillConfig.TaxCode, BillConfig.ReleaseEmailCc, BillConfig.ReleaseEmailBcc
					from BillConfig
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillConfig.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ID,
				int EmailOnReleased,
				int EmailOnUnreleased,
				string ReleaseEmailSubject,
				string ReleaseEmailBody,
				string TaxCode,
				string ReleaseEmailCc,
				string ReleaseEmailBcc
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillConfig where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillConfig.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillConfig.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillConfig(
						ID,
						EmailOnReleased,
						EmailOnUnreleased,
						ReleaseEmailSubject,
						ReleaseEmailBody,
						TaxCode,
						ReleaseEmailCc,
						ReleaseEmailBcc
						)
					values(
						@ID,
						@EmailOnReleased,
						@EmailOnUnreleased,
						@ReleaseEmailSubject,
						@ReleaseEmailBody,
						@TaxCode,
						@ReleaseEmailCc,
						@ReleaseEmailBcc
						)
					", ID, EmailOnReleased, EmailOnUnreleased, ReleaseEmailSubject, ReleaseEmailBody, TaxCode, ReleaseEmailCc, ReleaseEmailBcc);
                if (!_ok) m_db.LastError = "BillConfig.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int _old_ID,
				int _new_ID,
				int EmailOnReleased,
				int EmailOnUnreleased,
				string ReleaseEmailSubject,
				string ReleaseEmailBody,
				string TaxCode,
				string ReleaseEmailCc,
				string ReleaseEmailBcc
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillConfig where ID=@_old_ID", ref count, _old_ID))
				{
					m_db.LastError = "BillConfig.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillConfig.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillConfig
					set
						ID = @_new_ID,
						EmailOnReleased = @EmailOnReleased,
						EmailOnUnreleased = @EmailOnUnreleased,
						ReleaseEmailSubject = @ReleaseEmailSubject,
						ReleaseEmailBody = @ReleaseEmailBody,
						TaxCode = @TaxCode,
						ReleaseEmailCc = @ReleaseEmailCc,
						ReleaseEmailBcc = @ReleaseEmailBcc
					where ID=@_old_ID
					",
					_new_ID,
					EmailOnReleased,
					EmailOnUnreleased,
					ReleaseEmailSubject,
					ReleaseEmailBody,
					TaxCode,
					ReleaseEmailCc,
					ReleaseEmailBcc,
					_old_ID
				);
                if (!_ok) m_db.LastError = "BillConfig.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillConfig where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillConfig.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillConfig.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillConfig where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillConfig.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillCustomer
		//**********************************************************
		//  BillCustomer
		//**********************************************************
        CMD_BillCustomer m_BillCustomer = null;
        public CMD_BillCustomer BillCustomer
        {
            get
            {
				if (m_BillCustomer == null)
					m_BillCustomer = new CMD_BillCustomer(this);
				return m_BillCustomer;
			}
        }

		[Serializable]
		public class TBL_BillCustomer
		{
			public int ID { get; set; }
			public string BillType { get; set; }
			public string CustNo { get; set; }
			public string CustName1 { get; set; }
			public string CustName2 { get; set; }
			public string BUCode { get; set; }
			public string Address { get; set; }
			public string ContactPerson { get; set; }
			public string PaymentTerm { get; set; }
			public string SpecialInstruction { get; set; }
			public string GroupBy { get; set; }
			public int SiteID { get; set; }
			public string TelNo { get; set; }
			public string FaxNo { get; set; }
			public string EmailTo { get; set; }
			public string Remarks { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }

			public TBL_BillCustomer()
			{
				this.ID = 0;
				this.BillType = "";
				this.CustNo = "";
				this.CustName1 = "";
				this.CustName2 = "";
				this.BUCode = "";
				this.Address = "";
				this.ContactPerson = "";
				this.PaymentTerm = "";
				this.SpecialInstruction = "";
				this.GroupBy = "";
				this.SiteID = 0;
				this.TelNo = "";
				this.FaxNo = "";
				this.EmailTo = "";
				this.Remarks = "";
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_BillCustomer(int ID, string BillType, string CustNo, string CustName1, string CustName2, string BUCode, string Address, string ContactPerson, string PaymentTerm, string SpecialInstruction, string GroupBy, int SiteID, string TelNo, string FaxNo, string EmailTo, string Remarks, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime)
			{
				this.ID = ID;
				this.BillType = BillType;
				this.CustNo = CustNo;
				this.CustName1 = CustName1;
				this.CustName2 = CustName2;
				this.BUCode = BUCode;
				this.Address = Address;
				this.ContactPerson = ContactPerson;
				this.PaymentTerm = PaymentTerm;
				this.SpecialInstruction = SpecialInstruction;
				this.GroupBy = GroupBy;
				this.SiteID = SiteID;
				this.TelNo = TelNo;
				this.FaxNo = FaxNo;
				this.EmailTo = EmailTo;
				this.Remarks = Remarks;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
			}

			public void CopyTo(ref TBL_BillCustomer to)
			{
				to.ID = this.ID;
				to.BillType = this.BillType;
				to.CustNo = this.CustNo;
				to.CustName1 = this.CustName1;
				to.CustName2 = this.CustName2;
				to.BUCode = this.BUCode;
				to.Address = this.Address;
				to.ContactPerson = this.ContactPerson;
				to.PaymentTerm = this.PaymentTerm;
				to.SpecialInstruction = this.SpecialInstruction;
				to.GroupBy = this.GroupBy;
				to.SiteID = this.SiteID;
				to.TelNo = this.TelNo;
				to.FaxNo = this.FaxNo;
				to.EmailTo = this.EmailTo;
				to.Remarks = this.Remarks;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
			}

			public bool IsSame(TBL_BillCustomer x)
			{
				return(
					this.ID == x.ID &&
					this.BillType == x.BillType &&
					this.CustNo == x.CustNo &&
					this.CustName1 == x.CustName1 &&
					this.CustName2 == x.CustName2 &&
					this.BUCode == x.BUCode &&
					this.Address == x.Address &&
					this.ContactPerson == x.ContactPerson &&
					this.PaymentTerm == x.PaymentTerm &&
					this.SpecialInstruction == x.SpecialInstruction &&
					this.GroupBy == x.GroupBy &&
					this.SiteID == x.SiteID &&
					this.TelNo == x.TelNo &&
					this.FaxNo == x.FaxNo &&
					this.EmailTo == x.EmailTo &&
					this.Remarks == x.Remarks &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime
				);
			}

			public static TBL_BillCustomer ReadRow(DataRow row)
			{
				TBL_BillCustomer record = new TBL_BillCustomer();
				record.ID = get_int_value(row["ID"]);
				record.BillType = get_string_value(row["BillType"]);
				record.CustNo = get_string_value(row["CustNo"]);
				record.CustName1 = get_string_value(row["CustName1"]);
				record.CustName2 = get_string_value(row["CustName2"]);
				record.BUCode = get_string_value(row["BUCode"]);
				record.Address = get_string_value(row["Address"]);
				record.ContactPerson = get_string_value(row["ContactPerson"]);
				record.PaymentTerm = get_string_value(row["PaymentTerm"]);
				record.SpecialInstruction = get_string_value(row["SpecialInstruction"]);
				record.GroupBy = get_string_value(row["GroupBy"]);
				record.SiteID = get_int_value(row["SiteID"]);
				record.TelNo = get_string_value(row["TelNo"]);
				record.FaxNo = get_string_value(row["FaxNo"]);
				record.EmailTo = get_string_value(row["EmailTo"]);
				record.Remarks = get_string_value(row["Remarks"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				return record;
			}

			public static List<TBL_BillCustomer> ReadTable(DataTable dt)
			{
				List<TBL_BillCustomer> records = new List<TBL_BillCustomer>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillCustomer
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillCustomer(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, BillType, CustNo, CustName1, CustName2, BUCode, Address, ContactPerson, PaymentTerm, SpecialInstruction, GroupBy, SiteID, TelNo, FaxNo, EmailTo, Remarks, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from BillCustomer
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillCustomer.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillCustomer.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillCustomer data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillCustomer.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillCustomer.ID, BillCustomer.BillType, BillCustomer.CustNo, BillCustomer.CustName1, BillCustomer.CustName2, BillCustomer.BUCode, BillCustomer.Address, BillCustomer.ContactPerson, BillCustomer.PaymentTerm, BillCustomer.SpecialInstruction, BillCustomer.GroupBy, BillCustomer.SiteID, BillCustomer.TelNo, BillCustomer.FaxNo, BillCustomer.EmailTo, BillCustomer.Remarks, BillCustomer.CreatedBy, BillCustomer.CreatedDatetime, BillCustomer.ModifiedBy, BillCustomer.ModifiedDateTime
					from BillCustomer
					where BillCustomer.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillCustomer.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, BillType, CustNo, CustName1, CustName2, BUCode, Address, ContactPerson, PaymentTerm, SpecialInstruction, GroupBy, SiteID, TelNo, FaxNo, EmailTo, Remarks, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from BillCustomer
					", ref dt);
                if (!_ok) m_db.LastError = "BillCustomer.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillCustomer.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillCustomer.ID, BillCustomer.BillType, BillCustomer.CustNo, BillCustomer.CustName1, BillCustomer.CustName2, BillCustomer.BUCode, BillCustomer.Address, BillCustomer.ContactPerson, BillCustomer.PaymentTerm, BillCustomer.SpecialInstruction, BillCustomer.GroupBy, BillCustomer.SiteID, BillCustomer.TelNo, BillCustomer.FaxNo, BillCustomer.EmailTo, BillCustomer.Remarks, BillCustomer.CreatedBy, BillCustomer.CreatedDatetime, BillCustomer.ModifiedBy, BillCustomer.ModifiedDateTime
					from BillCustomer
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillCustomer.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillCustomer.ID, BillCustomer.BillType, BillCustomer.CustNo, BillCustomer.CustName1, BillCustomer.CustName2, BillCustomer.BUCode, BillCustomer.Address, BillCustomer.ContactPerson, BillCustomer.PaymentTerm, BillCustomer.SpecialInstruction, BillCustomer.GroupBy, BillCustomer.SiteID, BillCustomer.TelNo, BillCustomer.FaxNo, BillCustomer.EmailTo, BillCustomer.Remarks, BillCustomer.CreatedBy, BillCustomer.CreatedDatetime, BillCustomer.ModifiedBy, BillCustomer.ModifiedDateTime
					from BillCustomer
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillCustomer.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string BillType,
				string CustNo,
				string CustName1,
				string CustName2,
				string BUCode,
				string Address,
				string ContactPerson,
				string PaymentTerm,
				string SpecialInstruction,
				string GroupBy,
				int SiteID,
				string TelNo,
				string FaxNo,
				string EmailTo,
				string Remarks,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillCustomer(
						BillType,
						CustNo,
						CustName1,
						CustName2,
						BUCode,
						Address,
						ContactPerson,
						PaymentTerm,
						SpecialInstruction,
						GroupBy,
						SiteID,
						TelNo,
						FaxNo,
						EmailTo,
						Remarks,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime
						)
					values(
						@BillType,
						@CustNo,
						@CustName1,
						@CustName2,
						@BUCode,
						@Address,
						@ContactPerson,
						@PaymentTerm,
						@SpecialInstruction,
						@GroupBy,
						@SiteID,
						@TelNo,
						@FaxNo,
						@EmailTo,
						@Remarks,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime
						)
					", BillType, CustNo, CustName1, CustName2, BUCode, Address, ContactPerson, PaymentTerm, SpecialInstruction, GroupBy, SiteID, TelNo, FaxNo, EmailTo, Remarks, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime);
                if (!_ok) m_db.LastError = "BillCustomer.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string BillType,
				string CustNo,
				string CustName1,
				string CustName2,
				string BUCode,
				string Address,
				string ContactPerson,
				string PaymentTerm,
				string SpecialInstruction,
				string GroupBy,
				int SiteID,
				string TelNo,
				string FaxNo,
				string EmailTo,
				string Remarks,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillCustomer where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillCustomer.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillCustomer.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillCustomer
					set
						BillType = @BillType,
						CustNo = @CustNo,
						CustName1 = @CustName1,
						CustName2 = @CustName2,
						BUCode = @BUCode,
						Address = @Address,
						ContactPerson = @ContactPerson,
						PaymentTerm = @PaymentTerm,
						SpecialInstruction = @SpecialInstruction,
						GroupBy = @GroupBy,
						SiteID = @SiteID,
						TelNo = @TelNo,
						FaxNo = @FaxNo,
						EmailTo = @EmailTo,
						Remarks = @Remarks,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime
					where ID=@ID
					",
					BillType,
					CustNo,
					CustName1,
					CustName2,
					BUCode,
					Address,
					ContactPerson,
					PaymentTerm,
					SpecialInstruction,
					GroupBy,
					SiteID,
					TelNo,
					FaxNo,
					EmailTo,
					Remarks,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					ID
				);
                if (!_ok) m_db.LastError = "BillCustomer.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillCustomer where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillCustomer.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillCustomer.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillCustomer where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillCustomer.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillCustomerCC
		//**********************************************************
		//  BillCustomerCC
		//**********************************************************
        CMD_BillCustomerCC m_BillCustomerCC = null;
        public CMD_BillCustomerCC BillCustomerCC
        {
            get
            {
				if (m_BillCustomerCC == null)
					m_BillCustomerCC = new CMD_BillCustomerCC(this);
				return m_BillCustomerCC;
			}
        }

		[Serializable]
		public class TBL_BillCustomerCC
		{
			public int ID { get; set; }
			public int BillCustomerID { get; set; }
			public int CostCentreID { get; set; }

			public TBL_BillCustomerCC()
			{
				this.ID = 0;
				this.BillCustomerID = 0;
				this.CostCentreID = 0;
			}

			public TBL_BillCustomerCC(int ID, int BillCustomerID, int CostCentreID)
			{
				this.ID = ID;
				this.BillCustomerID = BillCustomerID;
				this.CostCentreID = CostCentreID;
			}

			public void CopyTo(ref TBL_BillCustomerCC to)
			{
				to.ID = this.ID;
				to.BillCustomerID = this.BillCustomerID;
				to.CostCentreID = this.CostCentreID;
			}

			public bool IsSame(TBL_BillCustomerCC x)
			{
				return(
					this.ID == x.ID &&
					this.BillCustomerID == x.BillCustomerID &&
					this.CostCentreID == x.CostCentreID
				);
			}

			public static TBL_BillCustomerCC ReadRow(DataRow row)
			{
				TBL_BillCustomerCC record = new TBL_BillCustomerCC();
				record.ID = get_int_value(row["ID"]);
				record.BillCustomerID = get_int_value(row["BillCustomerID"]);
				record.CostCentreID = get_int_value(row["CostCentreID"]);
				return record;
			}

			public static List<TBL_BillCustomerCC> ReadTable(DataTable dt)
			{
				List<TBL_BillCustomerCC> records = new List<TBL_BillCustomerCC>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillCustomerCC
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillCustomerCC(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, BillCustomerID, CostCentreID
					from BillCustomerCC
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillCustomerCC.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillCustomerCC.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillCustomerCC data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillCustomerCC.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillCustomerCC.ID, BillCustomerCC.BillCustomerID, BillCustomerCC.CostCentreID
					from BillCustomerCC
					where BillCustomerCC.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillCustomerCC.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, BillCustomerID, CostCentreID
					from BillCustomerCC
					", ref dt);
                if (!_ok) m_db.LastError = "BillCustomerCC.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillCustomerCC.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillCustomerCC.ID, BillCustomerCC.BillCustomerID, BillCustomerCC.CostCentreID
					from BillCustomerCC
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillCustomerCC.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillCustomerCC.ID, BillCustomerCC.BillCustomerID, BillCustomerCC.CostCentreID
					from BillCustomerCC
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillCustomerCC.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int BillCustomerID,
				int CostCentreID
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillCustomerCC(
						BillCustomerID,
						CostCentreID
						)
					values(
						@BillCustomerID,
						@CostCentreID
						)
					", BillCustomerID, CostCentreID);
                if (!_ok) m_db.LastError = "BillCustomerCC.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int BillCustomerID,
				int CostCentreID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillCustomerCC where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillCustomerCC.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillCustomerCC.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillCustomerCC
					set
						BillCustomerID = @BillCustomerID,
						CostCentreID = @CostCentreID
					where ID=@ID
					",
					BillCustomerID,
					CostCentreID,
					ID
				);
                if (!_ok) m_db.LastError = "BillCustomerCC.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillCustomerCC where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillCustomerCC.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillCustomerCC.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillCustomerCC where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillCustomerCC.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillItem
		//**********************************************************
		//  BillItem
		//**********************************************************
        CMD_BillItem m_BillItem = null;
        public CMD_BillItem BillItem
        {
            get
            {
				if (m_BillItem == null)
					m_BillItem = new CMD_BillItem(this);
				return m_BillItem;
			}
        }

		[Serializable]
		public class TBL_BillItem
		{
			public int ID { get; set; }
			public string ItemNo { get; set; }
			public string ItemName { get; set; }

			public TBL_BillItem()
			{
				this.ID = 0;
				this.ItemNo = "";
				this.ItemName = "";
			}

			public TBL_BillItem(int ID, string ItemNo, string ItemName)
			{
				this.ID = ID;
				this.ItemNo = ItemNo;
				this.ItemName = ItemName;
			}

			public void CopyTo(ref TBL_BillItem to)
			{
				to.ID = this.ID;
				to.ItemNo = this.ItemNo;
				to.ItemName = this.ItemName;
			}

			public bool IsSame(TBL_BillItem x)
			{
				return(
					this.ID == x.ID &&
					this.ItemNo == x.ItemNo &&
					this.ItemName == x.ItemName
				);
			}

			public static TBL_BillItem ReadRow(DataRow row)
			{
				TBL_BillItem record = new TBL_BillItem();
				record.ID = get_int_value(row["ID"]);
				record.ItemNo = get_string_value(row["ItemNo"]);
				record.ItemName = get_string_value(row["ItemName"]);
				return record;
			}

			public static List<TBL_BillItem> ReadTable(DataTable dt)
			{
				List<TBL_BillItem> records = new List<TBL_BillItem>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillItem
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillItem(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ItemNo, ItemName
					from BillItem
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillItem.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillItem.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillItem data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillItem.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillItem.ID, BillItem.ItemNo, BillItem.ItemName
					from BillItem
					where BillItem.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillItem.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ItemNo, ItemName
					from BillItem
					", ref dt);
                if (!_ok) m_db.LastError = "BillItem.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillItem.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillItem.ID, BillItem.ItemNo, BillItem.ItemName
					from BillItem
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillItem.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillItem.ID, BillItem.ItemNo, BillItem.ItemName
					from BillItem
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillItem.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string ItemNo,
				string ItemName
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillItem(
						ItemNo,
						ItemName
						)
					values(
						@ItemNo,
						@ItemName
						)
					", ItemNo, ItemName);
                if (!_ok) m_db.LastError = "BillItem.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string ItemNo,
				string ItemName
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillItem where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillItem.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillItem.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillItem
					set
						ItemNo = @ItemNo,
						ItemName = @ItemName
					where ID=@ID
					",
					ItemNo,
					ItemName,
					ID
				);
                if (!_ok) m_db.LastError = "BillItem.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillItem where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillItem.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillItem.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillItem where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillItem.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillMonthly
		//**********************************************************
		//  BillMonthly
		//**********************************************************
        CMD_BillMonthly m_BillMonthly = null;
        public CMD_BillMonthly BillMonthly
        {
            get
            {
				if (m_BillMonthly == null)
					m_BillMonthly = new CMD_BillMonthly(this);
				return m_BillMonthly;
			}
        }

		[Serializable]
		public class TBL_BillMonthly
		{
			public int ID { get; set; }
			public int BillPeriodID { get; set; }
			public int ServiceFormID { get; set; }
			public int OrgID { get; set; }
			public int SiteID { get; set; }
			public int CostCentreID { get; set; }
			public string Email { get; set; }
			public DateTime EffectiveDate { get; set; }
			public DateTime TerminatedDate { get; set; }
			public decimal UnitPrice { get; set; }
			public decimal OneTimeCharge { get; set; }
			public string Remarks { get; set; }
			public string AssetID { get; set; }

			public TBL_BillMonthly()
			{
				this.ID = 0;
				this.BillPeriodID = 0;
				this.ServiceFormID = 0;
				this.OrgID = 0;
				this.SiteID = 0;
				this.CostCentreID = 0;
				this.Email = "";
				this.EffectiveDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.TerminatedDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.UnitPrice = 0M;
				this.OneTimeCharge = 0M;
				this.Remarks = "";
				this.AssetID = "";
			}

			public TBL_BillMonthly(int ID, int BillPeriodID, int ServiceFormID, int OrgID, int SiteID, int CostCentreID, string Email, DateTime EffectiveDate, DateTime TerminatedDate, decimal UnitPrice, decimal OneTimeCharge, string Remarks, string AssetID)
			{
				this.ID = ID;
				this.BillPeriodID = BillPeriodID;
				this.ServiceFormID = ServiceFormID;
				this.OrgID = OrgID;
				this.SiteID = SiteID;
				this.CostCentreID = CostCentreID;
				this.Email = Email;
				this.EffectiveDate = EffectiveDate;
				this.TerminatedDate = TerminatedDate;
				this.UnitPrice = UnitPrice;
				this.OneTimeCharge = OneTimeCharge;
				this.Remarks = Remarks;
				this.AssetID = AssetID;
			}

			public void CopyTo(ref TBL_BillMonthly to)
			{
				to.ID = this.ID;
				to.BillPeriodID = this.BillPeriodID;
				to.ServiceFormID = this.ServiceFormID;
				to.OrgID = this.OrgID;
				to.SiteID = this.SiteID;
				to.CostCentreID = this.CostCentreID;
				to.Email = this.Email;
				to.EffectiveDate = this.EffectiveDate;
				to.TerminatedDate = this.TerminatedDate;
				to.UnitPrice = this.UnitPrice;
				to.OneTimeCharge = this.OneTimeCharge;
				to.Remarks = this.Remarks;
				to.AssetID = this.AssetID;
			}

			public bool IsSame(TBL_BillMonthly x)
			{
				return(
					this.ID == x.ID &&
					this.BillPeriodID == x.BillPeriodID &&
					this.ServiceFormID == x.ServiceFormID &&
					this.OrgID == x.OrgID &&
					this.SiteID == x.SiteID &&
					this.CostCentreID == x.CostCentreID &&
					this.Email == x.Email &&
					this.EffectiveDate == x.EffectiveDate &&
					this.TerminatedDate == x.TerminatedDate &&
					this.UnitPrice == x.UnitPrice &&
					this.OneTimeCharge == x.OneTimeCharge &&
					this.Remarks == x.Remarks &&
					this.AssetID == x.AssetID
				);
			}

			public static TBL_BillMonthly ReadRow(DataRow row)
			{
				TBL_BillMonthly record = new TBL_BillMonthly();
				record.ID = get_int_value(row["ID"]);
				record.BillPeriodID = get_int_value(row["BillPeriodID"]);
				record.ServiceFormID = get_int_value(row["ServiceFormID"]);
				record.OrgID = get_int_value(row["OrgID"]);
				record.SiteID = get_int_value(row["SiteID"]);
				record.CostCentreID = get_int_value(row["CostCentreID"]);
				record.Email = get_string_value(row["Email"]);
				record.EffectiveDate = get_DateTime_value(row["EffectiveDate"]);
				record.TerminatedDate = get_DateTime_value(row["TerminatedDate"]);
				record.UnitPrice = get_decimal_value(row["UnitPrice"]);
				record.OneTimeCharge = get_decimal_value(row["OneTimeCharge"]);
				record.Remarks = get_string_value(row["Remarks"]);
				record.AssetID = get_string_value(row["AssetID"]);
				return record;
			}

			public static List<TBL_BillMonthly> ReadTable(DataTable dt)
			{
				List<TBL_BillMonthly> records = new List<TBL_BillMonthly>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillMonthly
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillMonthly(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, BillPeriodID, ServiceFormID, OrgID, SiteID, CostCentreID, Email, EffectiveDate, TerminatedDate, UnitPrice, OneTimeCharge, Remarks, AssetID
					from BillMonthly
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillMonthly.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillMonthly.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillMonthly data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillMonthly.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillMonthly.ID, BillMonthly.BillPeriodID, BillMonthly.ServiceFormID, BillMonthly.OrgID, BillMonthly.SiteID, BillMonthly.CostCentreID, BillMonthly.Email, BillMonthly.EffectiveDate, BillMonthly.TerminatedDate, BillMonthly.UnitPrice, BillMonthly.OneTimeCharge, BillMonthly.Remarks, BillMonthly.AssetID
					from BillMonthly
					where BillMonthly.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillMonthly.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, BillPeriodID, ServiceFormID, OrgID, SiteID, CostCentreID, Email, EffectiveDate, TerminatedDate, UnitPrice, OneTimeCharge, Remarks, AssetID
					from BillMonthly
					", ref dt);
                if (!_ok) m_db.LastError = "BillMonthly.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillMonthly.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillMonthly.ID, BillMonthly.BillPeriodID, BillMonthly.ServiceFormID, BillMonthly.OrgID, BillMonthly.SiteID, BillMonthly.CostCentreID, BillMonthly.Email, BillMonthly.EffectiveDate, BillMonthly.TerminatedDate, BillMonthly.UnitPrice, BillMonthly.OneTimeCharge, BillMonthly.Remarks, BillMonthly.AssetID
					from BillMonthly
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillMonthly.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillMonthly.ID, BillMonthly.BillPeriodID, BillMonthly.ServiceFormID, BillMonthly.OrgID, BillMonthly.SiteID, BillMonthly.CostCentreID, BillMonthly.Email, BillMonthly.EffectiveDate, BillMonthly.TerminatedDate, BillMonthly.UnitPrice, BillMonthly.OneTimeCharge, BillMonthly.Remarks, BillMonthly.AssetID
					from BillMonthly
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillMonthly.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int BillPeriodID,
				int ServiceFormID,
				int OrgID,
				int SiteID,
				int CostCentreID,
				string Email,
				DateTime EffectiveDate,
				DateTime TerminatedDate,
				decimal UnitPrice,
				decimal OneTimeCharge,
				string Remarks,
				string AssetID
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillMonthly(
						BillPeriodID,
						ServiceFormID,
						OrgID,
						SiteID,
						CostCentreID,
						Email,
						EffectiveDate,
						TerminatedDate,
						UnitPrice,
						OneTimeCharge,
						Remarks,
						AssetID
						)
					values(
						@BillPeriodID,
						@ServiceFormID,
						@OrgID,
						@SiteID,
						@CostCentreID,
						@Email,
						@EffectiveDate,
						@TerminatedDate,
						@UnitPrice,
						@OneTimeCharge,
						@Remarks,
						@AssetID
						)
					", BillPeriodID, ServiceFormID, OrgID, SiteID, CostCentreID, Email, EffectiveDate, TerminatedDate, UnitPrice, OneTimeCharge, Remarks, AssetID);
                if (!_ok) m_db.LastError = "BillMonthly.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int BillPeriodID,
				int ServiceFormID,
				int OrgID,
				int SiteID,
				int CostCentreID,
				string Email,
				DateTime EffectiveDate,
				DateTime TerminatedDate,
				decimal UnitPrice,
				decimal OneTimeCharge,
				string Remarks,
				string AssetID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillMonthly where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillMonthly.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillMonthly.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillMonthly
					set
						BillPeriodID = @BillPeriodID,
						ServiceFormID = @ServiceFormID,
						OrgID = @OrgID,
						SiteID = @SiteID,
						CostCentreID = @CostCentreID,
						Email = @Email,
						EffectiveDate = @EffectiveDate,
						TerminatedDate = @TerminatedDate,
						UnitPrice = @UnitPrice,
						OneTimeCharge = @OneTimeCharge,
						Remarks = @Remarks,
						AssetID = @AssetID
					where ID=@ID
					",
					BillPeriodID,
					ServiceFormID,
					OrgID,
					SiteID,
					CostCentreID,
					Email,
					EffectiveDate,
					TerminatedDate,
					UnitPrice,
					OneTimeCharge,
					Remarks,
					AssetID,
					ID
				);
                if (!_ok) m_db.LastError = "BillMonthly.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillMonthly where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillMonthly.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillMonthly.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillMonthly where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillMonthly.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillPeriod
		//**********************************************************
		//  BillPeriod
		//**********************************************************
        CMD_BillPeriod m_BillPeriod = null;
        public CMD_BillPeriod BillPeriod
        {
            get
            {
				if (m_BillPeriod == null)
					m_BillPeriod = new CMD_BillPeriod(this);
				return m_BillPeriod;
			}
        }

		[Serializable]
		public class TBL_BillPeriod
		{
			public int ID { get; set; }
			public string Year0 { get; set; }
			public string Month0 { get; set; }
			public DateTime StartDate { get; set; }
			public DateTime EndDate { get; set; }

			public TBL_BillPeriod()
			{
				this.ID = 0;
				this.Year0 = "";
				this.Month0 = "";
				this.StartDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.EndDate = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_BillPeriod(int ID, string Year0, string Month0, DateTime StartDate, DateTime EndDate)
			{
				this.ID = ID;
				this.Year0 = Year0;
				this.Month0 = Month0;
				this.StartDate = StartDate;
				this.EndDate = EndDate;
			}

			public void CopyTo(ref TBL_BillPeriod to)
			{
				to.ID = this.ID;
				to.Year0 = this.Year0;
				to.Month0 = this.Month0;
				to.StartDate = this.StartDate;
				to.EndDate = this.EndDate;
			}

			public bool IsSame(TBL_BillPeriod x)
			{
				return(
					this.ID == x.ID &&
					this.Year0 == x.Year0 &&
					this.Month0 == x.Month0 &&
					this.StartDate == x.StartDate &&
					this.EndDate == x.EndDate
				);
			}

			public static TBL_BillPeriod ReadRow(DataRow row)
			{
				TBL_BillPeriod record = new TBL_BillPeriod();
				record.ID = get_int_value(row["ID"]);
				record.Year0 = get_string_value(row["Year0"]);
				record.Month0 = get_string_value(row["Month0"]);
				record.StartDate = get_DateTime_value(row["StartDate"]);
				record.EndDate = get_DateTime_value(row["EndDate"]);
				return record;
			}

			public static List<TBL_BillPeriod> ReadTable(DataTable dt)
			{
				List<TBL_BillPeriod> records = new List<TBL_BillPeriod>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillPeriod
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillPeriod(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, Year0, Month0, StartDate, EndDate
					from BillPeriod
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillPeriod.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillPeriod.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillPeriod data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillPeriod.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillPeriod.ID, BillPeriod.Year0, BillPeriod.Month0, BillPeriod.StartDate, BillPeriod.EndDate
					from BillPeriod
					where BillPeriod.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillPeriod.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, Year0, Month0, StartDate, EndDate
					from BillPeriod
					", ref dt);
                if (!_ok) m_db.LastError = "BillPeriod.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillPeriod.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillPeriod.ID, BillPeriod.Year0, BillPeriod.Month0, BillPeriod.StartDate, BillPeriod.EndDate
					from BillPeriod
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillPeriod.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillPeriod.ID, BillPeriod.Year0, BillPeriod.Month0, BillPeriod.StartDate, BillPeriod.EndDate
					from BillPeriod
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillPeriod.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string Year0,
				string Month0,
				DateTime StartDate,
				DateTime EndDate
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillPeriod(
						Year0,
						Month0,
						StartDate,
						EndDate
						)
					values(
						@Year0,
						@Month0,
						@StartDate,
						@EndDate
						)
					", Year0, Month0, StartDate, EndDate);
                if (!_ok) m_db.LastError = "BillPeriod.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string Year0,
				string Month0,
				DateTime StartDate,
				DateTime EndDate
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillPeriod where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillPeriod.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillPeriod.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillPeriod
					set
						Year0 = @Year0,
						Month0 = @Month0,
						StartDate = @StartDate,
						EndDate = @EndDate
					where ID=@ID
					",
					Year0,
					Month0,
					StartDate,
					EndDate,
					ID
				);
                if (!_ok) m_db.LastError = "BillPeriod.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillPeriod where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillPeriod.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillPeriod.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillPeriod where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillPeriod.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillPricing
		//**********************************************************
		//  BillPricing
		//**********************************************************
        CMD_BillPricing m_BillPricing = null;
        public CMD_BillPricing BillPricing
        {
            get
            {
				if (m_BillPricing == null)
					m_BillPricing = new CMD_BillPricing(this);
				return m_BillPricing;
			}
        }

		[Serializable]
		public class TBL_BillPricing
		{
			public int ID { get; set; }
			public int BillPeriodIDFrom { get; set; }
			public int BillPeriodIDTo { get; set; }
			public string BillItem { get; set; }
			public decimal ValueDec { get; set; }
			public string ValueStr { get; set; }

			public TBL_BillPricing()
			{
				this.ID = 0;
				this.BillPeriodIDFrom = 0;
				this.BillPeriodIDTo = 0;
				this.BillItem = "";
				this.ValueDec = 0M;
				this.ValueStr = "";
			}

			public TBL_BillPricing(int ID, int BillPeriodIDFrom, int BillPeriodIDTo, string BillItem, decimal ValueDec, string ValueStr)
			{
				this.ID = ID;
				this.BillPeriodIDFrom = BillPeriodIDFrom;
				this.BillPeriodIDTo = BillPeriodIDTo;
				this.BillItem = BillItem;
				this.ValueDec = ValueDec;
				this.ValueStr = ValueStr;
			}

			public void CopyTo(ref TBL_BillPricing to)
			{
				to.ID = this.ID;
				to.BillPeriodIDFrom = this.BillPeriodIDFrom;
				to.BillPeriodIDTo = this.BillPeriodIDTo;
				to.BillItem = this.BillItem;
				to.ValueDec = this.ValueDec;
				to.ValueStr = this.ValueStr;
			}

			public bool IsSame(TBL_BillPricing x)
			{
				return(
					this.ID == x.ID &&
					this.BillPeriodIDFrom == x.BillPeriodIDFrom &&
					this.BillPeriodIDTo == x.BillPeriodIDTo &&
					this.BillItem == x.BillItem &&
					this.ValueDec == x.ValueDec &&
					this.ValueStr == x.ValueStr
				);
			}

			public static TBL_BillPricing ReadRow(DataRow row)
			{
				TBL_BillPricing record = new TBL_BillPricing();
				record.ID = get_int_value(row["ID"]);
				record.BillPeriodIDFrom = get_int_value(row["BillPeriodIDFrom"]);
				record.BillPeriodIDTo = get_int_value(row["BillPeriodIDTo"]);
				record.BillItem = get_string_value(row["BillItem"]);
				record.ValueDec = get_decimal_value(row["ValueDec"]);
				record.ValueStr = get_string_value(row["ValueStr"]);
				return record;
			}

			public static List<TBL_BillPricing> ReadTable(DataTable dt)
			{
				List<TBL_BillPricing> records = new List<TBL_BillPricing>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillPricing
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillPricing(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, BillPeriodIDFrom, BillPeriodIDTo, BillItem, ValueDec, ValueStr
					from BillPricing
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillPricing.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillPricing.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillPricing data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillPricing.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillPricing.ID, BillPricing.BillPeriodIDFrom, BillPricing.BillPeriodIDTo, BillPricing.BillItem, BillPricing.ValueDec, BillPricing.ValueStr
					from BillPricing
					where BillPricing.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillPricing.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, BillPeriodIDFrom, BillPeriodIDTo, BillItem, ValueDec, ValueStr
					from BillPricing
					", ref dt);
                if (!_ok) m_db.LastError = "BillPricing.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillPricing.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillPricing.ID, BillPricing.BillPeriodIDFrom, BillPricing.BillPeriodIDTo, BillPricing.BillItem, BillPricing.ValueDec, BillPricing.ValueStr
					from BillPricing
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillPricing.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillPricing.ID, BillPricing.BillPeriodIDFrom, BillPricing.BillPeriodIDTo, BillPricing.BillItem, BillPricing.ValueDec, BillPricing.ValueStr
					from BillPricing
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillPricing.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int BillPeriodIDFrom,
				int BillPeriodIDTo,
				string BillItem,
				decimal ValueDec,
				string ValueStr
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillPricing(
						BillPeriodIDFrom,
						BillPeriodIDTo,
						BillItem,
						ValueDec,
						ValueStr
						)
					values(
						@BillPeriodIDFrom,
						@BillPeriodIDTo,
						@BillItem,
						@ValueDec,
						@ValueStr
						)
					", BillPeriodIDFrom, BillPeriodIDTo, BillItem, ValueDec, ValueStr);
                if (!_ok) m_db.LastError = "BillPricing.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int BillPeriodIDFrom,
				int BillPeriodIDTo,
				string BillItem,
				decimal ValueDec,
				string ValueStr
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillPricing where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillPricing.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillPricing.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillPricing
					set
						BillPeriodIDFrom = @BillPeriodIDFrom,
						BillPeriodIDTo = @BillPeriodIDTo,
						BillItem = @BillItem,
						ValueDec = @ValueDec,
						ValueStr = @ValueStr
					where ID=@ID
					",
					BillPeriodIDFrom,
					BillPeriodIDTo,
					BillItem,
					ValueDec,
					ValueStr,
					ID
				);
                if (!_ok) m_db.LastError = "BillPricing.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillPricing where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillPricing.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillPricing.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillPricing where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillPricing.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillReportRepository
		//**********************************************************
		//  BillReportRepository
		//**********************************************************
        CMD_BillReportRepository m_BillReportRepository = null;
        public CMD_BillReportRepository BillReportRepository
        {
            get
            {
				if (m_BillReportRepository == null)
					m_BillReportRepository = new CMD_BillReportRepository(this);
				return m_BillReportRepository;
			}
        }

		[Serializable]
		public class TBL_BillReportRepository
		{
			public int ID { get; set; }
			public int BillPeriodID { get; set; }
			public int BillReportTemplateID { get; set; }
			public string ReportFileName { get; set; }
			public byte[] ReportData { get; set; }
			public string ContentType { get; set; }
			public int IsReleased { get; set; }
			public int SiteID { get; set; }
			public int CostCentreID { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDateTime { get; set; }
			public int ReleasedBy { get; set; }
			public DateTime ReleasedDateTime { get; set; }
			public string DownloadID { get; set; }
			public int UnReleasedBy { get; set; }
			public DateTime UnReleasedDateTime { get; set; }
			public int BillCustomerID { get; set; }

			public TBL_BillReportRepository()
			{
				this.ID = 0;
				this.BillPeriodID = 0;
				this.BillReportTemplateID = 0;
				this.ReportFileName = "";
				this.ReportData = new byte[0];
				this.ContentType = "";
				this.IsReleased = 0;
				this.SiteID = 0;
				this.CostCentreID = 0;
				this.CreatedBy = 0;
				this.CreatedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ReleasedBy = 0;
				this.ReleasedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.DownloadID = "";
				this.UnReleasedBy = 0;
				this.UnReleasedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.BillCustomerID = 0;
			}

			public TBL_BillReportRepository(int ID, int BillPeriodID, int BillReportTemplateID, string ReportFileName, byte[] ReportData, string ContentType, int IsReleased, int SiteID, int CostCentreID, int CreatedBy, DateTime CreatedDateTime, int ReleasedBy, DateTime ReleasedDateTime, string DownloadID, int UnReleasedBy, DateTime UnReleasedDateTime, int BillCustomerID)
			{
				this.ID = ID;
				this.BillPeriodID = BillPeriodID;
				this.BillReportTemplateID = BillReportTemplateID;
				this.ReportFileName = ReportFileName;
				this.ReportData = ReportData;
				this.ContentType = ContentType;
				this.IsReleased = IsReleased;
				this.SiteID = SiteID;
				this.CostCentreID = CostCentreID;
				this.CreatedBy = CreatedBy;
				this.CreatedDateTime = CreatedDateTime;
				this.ReleasedBy = ReleasedBy;
				this.ReleasedDateTime = ReleasedDateTime;
				this.DownloadID = DownloadID;
				this.UnReleasedBy = UnReleasedBy;
				this.UnReleasedDateTime = UnReleasedDateTime;
				this.BillCustomerID = BillCustomerID;
			}

			public void CopyTo(ref TBL_BillReportRepository to)
			{
				to.ID = this.ID;
				to.BillPeriodID = this.BillPeriodID;
				to.BillReportTemplateID = this.BillReportTemplateID;
				to.ReportFileName = this.ReportFileName;
				to.ReportData = this.ReportData;
				to.ContentType = this.ContentType;
				to.IsReleased = this.IsReleased;
				to.SiteID = this.SiteID;
				to.CostCentreID = this.CostCentreID;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDateTime = this.CreatedDateTime;
				to.ReleasedBy = this.ReleasedBy;
				to.ReleasedDateTime = this.ReleasedDateTime;
				to.DownloadID = this.DownloadID;
				to.UnReleasedBy = this.UnReleasedBy;
				to.UnReleasedDateTime = this.UnReleasedDateTime;
				to.BillCustomerID = this.BillCustomerID;
			}

			public bool IsSame(TBL_BillReportRepository x)
			{
				return(
					this.ID == x.ID &&
					this.BillPeriodID == x.BillPeriodID &&
					this.BillReportTemplateID == x.BillReportTemplateID &&
					this.ReportFileName == x.ReportFileName &&
					this.ReportData == x.ReportData &&
					this.ContentType == x.ContentType &&
					this.IsReleased == x.IsReleased &&
					this.SiteID == x.SiteID &&
					this.CostCentreID == x.CostCentreID &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDateTime == x.CreatedDateTime &&
					this.ReleasedBy == x.ReleasedBy &&
					this.ReleasedDateTime == x.ReleasedDateTime &&
					this.DownloadID == x.DownloadID &&
					this.UnReleasedBy == x.UnReleasedBy &&
					this.UnReleasedDateTime == x.UnReleasedDateTime &&
					this.BillCustomerID == x.BillCustomerID
				);
			}

			public static TBL_BillReportRepository ReadRow(DataRow row)
			{
				TBL_BillReportRepository record = new TBL_BillReportRepository();
				record.ID = get_int_value(row["ID"]);
				record.BillPeriodID = get_int_value(row["BillPeriodID"]);
				record.BillReportTemplateID = get_int_value(row["BillReportTemplateID"]);
				record.ReportFileName = get_string_value(row["ReportFileName"]);
				record.ReportData = get_bytes_value(row["ReportData"]);
				record.ContentType = get_string_value(row["ContentType"]);
				record.IsReleased = get_int_value(row["IsReleased"]);
				record.SiteID = get_int_value(row["SiteID"]);
				record.CostCentreID = get_int_value(row["CostCentreID"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDateTime = get_DateTime_value(row["CreatedDateTime"]);
				record.ReleasedBy = get_int_value(row["ReleasedBy"]);
				record.ReleasedDateTime = get_DateTime_value(row["ReleasedDateTime"]);
				record.DownloadID = get_string_value(row["DownloadID"]);
				record.UnReleasedBy = get_int_value(row["UnReleasedBy"]);
				record.UnReleasedDateTime = get_DateTime_value(row["UnReleasedDateTime"]);
				record.BillCustomerID = get_int_value(row["BillCustomerID"]);
				return record;
			}

			public static List<TBL_BillReportRepository> ReadTable(DataTable dt)
			{
				List<TBL_BillReportRepository> records = new List<TBL_BillReportRepository>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillReportRepository
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillReportRepository(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, BillPeriodID, BillReportTemplateID, ReportFileName, ReportData, ContentType, IsReleased, SiteID, CostCentreID, CreatedBy, CreatedDateTime, ReleasedBy, ReleasedDateTime, DownloadID, UnReleasedBy, UnReleasedDateTime, BillCustomerID
					from BillReportRepository
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillReportRepository.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillReportRepository.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillReportRepository data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillReportRepository.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportRepository.ID, BillReportRepository.BillPeriodID, BillReportRepository.BillReportTemplateID, BillReportRepository.ReportFileName, BillReportRepository.ReportData, BillReportRepository.ContentType, BillReportRepository.IsReleased, BillReportRepository.SiteID, BillReportRepository.CostCentreID, BillReportRepository.CreatedBy, BillReportRepository.CreatedDateTime, BillReportRepository.ReleasedBy, BillReportRepository.ReleasedDateTime, BillReportRepository.DownloadID, BillReportRepository.UnReleasedBy, BillReportRepository.UnReleasedDateTime, BillReportRepository.BillCustomerID
					from BillReportRepository
					where BillReportRepository.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillReportRepository.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, BillPeriodID, BillReportTemplateID, ReportFileName, ReportData, ContentType, IsReleased, SiteID, CostCentreID, CreatedBy, CreatedDateTime, ReleasedBy, ReleasedDateTime, DownloadID, UnReleasedBy, UnReleasedDateTime, BillCustomerID
					from BillReportRepository
					", ref dt);
                if (!_ok) m_db.LastError = "BillReportRepository.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillReportRepository.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportRepository.ID, BillReportRepository.BillPeriodID, BillReportRepository.BillReportTemplateID, BillReportRepository.ReportFileName, BillReportRepository.ReportData, BillReportRepository.ContentType, BillReportRepository.IsReleased, BillReportRepository.SiteID, BillReportRepository.CostCentreID, BillReportRepository.CreatedBy, BillReportRepository.CreatedDateTime, BillReportRepository.ReleasedBy, BillReportRepository.ReleasedDateTime, BillReportRepository.DownloadID, BillReportRepository.UnReleasedBy, BillReportRepository.UnReleasedDateTime, BillReportRepository.BillCustomerID
					from BillReportRepository
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillReportRepository.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportRepository.ID, BillReportRepository.BillPeriodID, BillReportRepository.BillReportTemplateID, BillReportRepository.ReportFileName, BillReportRepository.ReportData, BillReportRepository.ContentType, BillReportRepository.IsReleased, BillReportRepository.SiteID, BillReportRepository.CostCentreID, BillReportRepository.CreatedBy, BillReportRepository.CreatedDateTime, BillReportRepository.ReleasedBy, BillReportRepository.ReleasedDateTime, BillReportRepository.DownloadID, BillReportRepository.UnReleasedBy, BillReportRepository.UnReleasedDateTime, BillReportRepository.BillCustomerID
					from BillReportRepository
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillReportRepository.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int BillPeriodID,
				int BillReportTemplateID,
				string ReportFileName,
				byte[] ReportData,
				string ContentType,
				int IsReleased,
				int SiteID,
				int CostCentreID,
				int CreatedBy,
				DateTime CreatedDateTime,
				int ReleasedBy,
				DateTime ReleasedDateTime,
				string DownloadID,
				int UnReleasedBy,
				DateTime UnReleasedDateTime,
				int BillCustomerID
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillReportRepository(
						BillPeriodID,
						BillReportTemplateID,
						ReportFileName,
						ReportData,
						ContentType,
						IsReleased,
						SiteID,
						CostCentreID,
						CreatedBy,
						CreatedDateTime,
						ReleasedBy,
						ReleasedDateTime,
						DownloadID,
						UnReleasedBy,
						UnReleasedDateTime,
						BillCustomerID
						)
					values(
						@BillPeriodID,
						@BillReportTemplateID,
						@ReportFileName,
						@ReportData,
						@ContentType,
						@IsReleased,
						@SiteID,
						@CostCentreID,
						@CreatedBy,
						@CreatedDateTime,
						@ReleasedBy,
						@ReleasedDateTime,
						@DownloadID,
						@UnReleasedBy,
						@UnReleasedDateTime,
						@BillCustomerID
						)
					", BillPeriodID, BillReportTemplateID, ReportFileName, ReportData, ContentType, IsReleased, SiteID, CostCentreID, CreatedBy, CreatedDateTime, ReleasedBy, ReleasedDateTime, DownloadID, UnReleasedBy, UnReleasedDateTime, BillCustomerID);
                if (!_ok) m_db.LastError = "BillReportRepository.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int BillPeriodID,
				int BillReportTemplateID,
				string ReportFileName,
				byte[] ReportData,
				string ContentType,
				int IsReleased,
				int SiteID,
				int CostCentreID,
				int CreatedBy,
				DateTime CreatedDateTime,
				int ReleasedBy,
				DateTime ReleasedDateTime,
				string DownloadID,
				int UnReleasedBy,
				DateTime UnReleasedDateTime,
				int BillCustomerID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportRepository where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillReportRepository.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportRepository.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillReportRepository
					set
						BillPeriodID = @BillPeriodID,
						BillReportTemplateID = @BillReportTemplateID,
						ReportFileName = @ReportFileName,
						ReportData = @ReportData,
						ContentType = @ContentType,
						IsReleased = @IsReleased,
						SiteID = @SiteID,
						CostCentreID = @CostCentreID,
						CreatedBy = @CreatedBy,
						CreatedDateTime = @CreatedDateTime,
						ReleasedBy = @ReleasedBy,
						ReleasedDateTime = @ReleasedDateTime,
						DownloadID = @DownloadID,
						UnReleasedBy = @UnReleasedBy,
						UnReleasedDateTime = @UnReleasedDateTime,
						BillCustomerID = @BillCustomerID
					where ID=@ID
					",
					BillPeriodID,
					BillReportTemplateID,
					ReportFileName,
					ReportData,
					ContentType,
					IsReleased,
					SiteID,
					CostCentreID,
					CreatedBy,
					CreatedDateTime,
					ReleasedBy,
					ReleasedDateTime,
					DownloadID,
					UnReleasedBy,
					UnReleasedDateTime,
					BillCustomerID,
					ID
				);
                if (!_ok) m_db.LastError = "BillReportRepository.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportRepository where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillReportRepository.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportRepository.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillReportRepository where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillReportRepository.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillReportTemplate
		//**********************************************************
		//  BillReportTemplate
		//**********************************************************
        CMD_BillReportTemplate m_BillReportTemplate = null;
        public CMD_BillReportTemplate BillReportTemplate
        {
            get
            {
				if (m_BillReportTemplate == null)
					m_BillReportTemplate = new CMD_BillReportTemplate(this);
				return m_BillReportTemplate;
			}
        }

		[Serializable]
		public class TBL_BillReportTemplate
		{
			public int ID { get; set; }
			public string ReportName { get; set; }
			public string ReportPath { get; set; }
			public string RenderFormat { get; set; }
			public string ReportFileExt { get; set; }
			public string ContentType { get; set; }
			public string DatasetName { get; set; }
			public string StoredProcName { get; set; }
			public string ParameterType { get; set; }
			public int ReportStatus { get; set; }
			public string BillType { get; set; }

			public TBL_BillReportTemplate()
			{
				this.ID = 0;
				this.ReportName = "";
				this.ReportPath = "";
				this.RenderFormat = "";
				this.ReportFileExt = "";
				this.ContentType = "";
				this.DatasetName = "";
				this.StoredProcName = "";
				this.ParameterType = "";
				this.ReportStatus = 0;
				this.BillType = "";
			}

			public TBL_BillReportTemplate(int ID, string ReportName, string ReportPath, string RenderFormat, string ReportFileExt, string ContentType, string DatasetName, string StoredProcName, string ParameterType, int ReportStatus, string BillType)
			{
				this.ID = ID;
				this.ReportName = ReportName;
				this.ReportPath = ReportPath;
				this.RenderFormat = RenderFormat;
				this.ReportFileExt = ReportFileExt;
				this.ContentType = ContentType;
				this.DatasetName = DatasetName;
				this.StoredProcName = StoredProcName;
				this.ParameterType = ParameterType;
				this.ReportStatus = ReportStatus;
				this.BillType = BillType;
			}

			public void CopyTo(ref TBL_BillReportTemplate to)
			{
				to.ID = this.ID;
				to.ReportName = this.ReportName;
				to.ReportPath = this.ReportPath;
				to.RenderFormat = this.RenderFormat;
				to.ReportFileExt = this.ReportFileExt;
				to.ContentType = this.ContentType;
				to.DatasetName = this.DatasetName;
				to.StoredProcName = this.StoredProcName;
				to.ParameterType = this.ParameterType;
				to.ReportStatus = this.ReportStatus;
				to.BillType = this.BillType;
			}

			public bool IsSame(TBL_BillReportTemplate x)
			{
				return(
					this.ID == x.ID &&
					this.ReportName == x.ReportName &&
					this.ReportPath == x.ReportPath &&
					this.RenderFormat == x.RenderFormat &&
					this.ReportFileExt == x.ReportFileExt &&
					this.ContentType == x.ContentType &&
					this.DatasetName == x.DatasetName &&
					this.StoredProcName == x.StoredProcName &&
					this.ParameterType == x.ParameterType &&
					this.ReportStatus == x.ReportStatus &&
					this.BillType == x.BillType
				);
			}

			public static TBL_BillReportTemplate ReadRow(DataRow row)
			{
				TBL_BillReportTemplate record = new TBL_BillReportTemplate();
				record.ID = get_int_value(row["ID"]);
				record.ReportName = get_string_value(row["ReportName"]);
				record.ReportPath = get_string_value(row["ReportPath"]);
				record.RenderFormat = get_string_value(row["RenderFormat"]);
				record.ReportFileExt = get_string_value(row["ReportFileExt"]);
				record.ContentType = get_string_value(row["ContentType"]);
				record.DatasetName = get_string_value(row["DatasetName"]);
				record.StoredProcName = get_string_value(row["StoredProcName"]);
				record.ParameterType = get_string_value(row["ParameterType"]);
				record.ReportStatus = get_int_value(row["ReportStatus"]);
				record.BillType = get_string_value(row["BillType"]);
				return record;
			}

			public static List<TBL_BillReportTemplate> ReadTable(DataTable dt)
			{
				List<TBL_BillReportTemplate> records = new List<TBL_BillReportTemplate>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillReportTemplate
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillReportTemplate(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ReportName, ReportPath, RenderFormat, ReportFileExt, ContentType, DatasetName, StoredProcName, ParameterType, ReportStatus, BillType
					from BillReportTemplate
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillReportTemplate.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillReportTemplate.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillReportTemplate data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillReportTemplate.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportTemplate.ID, BillReportTemplate.ReportName, BillReportTemplate.ReportPath, BillReportTemplate.RenderFormat, BillReportTemplate.ReportFileExt, BillReportTemplate.ContentType, BillReportTemplate.DatasetName, BillReportTemplate.StoredProcName, BillReportTemplate.ParameterType, BillReportTemplate.ReportStatus, BillReportTemplate.BillType
					from BillReportTemplate
					where BillReportTemplate.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillReportTemplate.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ReportName, ReportPath, RenderFormat, ReportFileExt, ContentType, DatasetName, StoredProcName, ParameterType, ReportStatus, BillType
					from BillReportTemplate
					", ref dt);
                if (!_ok) m_db.LastError = "BillReportTemplate.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillReportTemplate.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportTemplate.ID, BillReportTemplate.ReportName, BillReportTemplate.ReportPath, BillReportTemplate.RenderFormat, BillReportTemplate.ReportFileExt, BillReportTemplate.ContentType, BillReportTemplate.DatasetName, BillReportTemplate.StoredProcName, BillReportTemplate.ParameterType, BillReportTemplate.ReportStatus, BillReportTemplate.BillType
					from BillReportTemplate
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillReportTemplate.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportTemplate.ID, BillReportTemplate.ReportName, BillReportTemplate.ReportPath, BillReportTemplate.RenderFormat, BillReportTemplate.ReportFileExt, BillReportTemplate.ContentType, BillReportTemplate.DatasetName, BillReportTemplate.StoredProcName, BillReportTemplate.ParameterType, BillReportTemplate.ReportStatus, BillReportTemplate.BillType
					from BillReportTemplate
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillReportTemplate.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ID,
				string ReportName,
				string ReportPath,
				string RenderFormat,
				string ReportFileExt,
				string ContentType,
				string DatasetName,
				string StoredProcName,
				string ParameterType,
				int ReportStatus,
				string BillType
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportTemplate where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillReportTemplate.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportTemplate.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillReportTemplate(
						ID,
						ReportName,
						ReportPath,
						RenderFormat,
						ReportFileExt,
						ContentType,
						DatasetName,
						StoredProcName,
						ParameterType,
						ReportStatus,
						BillType
						)
					values(
						@ID,
						@ReportName,
						@ReportPath,
						@RenderFormat,
						@ReportFileExt,
						@ContentType,
						@DatasetName,
						@StoredProcName,
						@ParameterType,
						@ReportStatus,
						@BillType
						)
					", ID, ReportName, ReportPath, RenderFormat, ReportFileExt, ContentType, DatasetName, StoredProcName, ParameterType, ReportStatus, BillType);
                if (!_ok) m_db.LastError = "BillReportTemplate.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int _old_ID,
				int _new_ID,
				string ReportName,
				string ReportPath,
				string RenderFormat,
				string ReportFileExt,
				string ContentType,
				string DatasetName,
				string StoredProcName,
				string ParameterType,
				int ReportStatus,
				string BillType
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportTemplate where ID=@_old_ID", ref count, _old_ID))
				{
					m_db.LastError = "BillReportTemplate.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportTemplate.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillReportTemplate
					set
						ID = @_new_ID,
						ReportName = @ReportName,
						ReportPath = @ReportPath,
						RenderFormat = @RenderFormat,
						ReportFileExt = @ReportFileExt,
						ContentType = @ContentType,
						DatasetName = @DatasetName,
						StoredProcName = @StoredProcName,
						ParameterType = @ParameterType,
						ReportStatus = @ReportStatus,
						BillType = @BillType
					where ID=@_old_ID
					",
					_new_ID,
					ReportName,
					ReportPath,
					RenderFormat,
					ReportFileExt,
					ContentType,
					DatasetName,
					StoredProcName,
					ParameterType,
					ReportStatus,
					BillType,
					_old_ID
				);
                if (!_ok) m_db.LastError = "BillReportTemplate.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportTemplate where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillReportTemplate.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportTemplate.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillReportTemplate where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillReportTemplate.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region BillReportUserGroup
		//**********************************************************
		//  BillReportUserGroup
		//**********************************************************
        CMD_BillReportUserGroup m_BillReportUserGroup = null;
        public CMD_BillReportUserGroup BillReportUserGroup
        {
            get
            {
				if (m_BillReportUserGroup == null)
					m_BillReportUserGroup = new CMD_BillReportUserGroup(this);
				return m_BillReportUserGroup;
			}
        }

		[Serializable]
		public class TBL_BillReportUserGroup
		{
			public int ID { get; set; }
			public int BillReportTemplateID { get; set; }
			public int GroupMemberID { get; set; }

			public TBL_BillReportUserGroup()
			{
				this.ID = 0;
				this.BillReportTemplateID = 0;
				this.GroupMemberID = 0;
			}

			public TBL_BillReportUserGroup(int ID, int BillReportTemplateID, int GroupMemberID)
			{
				this.ID = ID;
				this.BillReportTemplateID = BillReportTemplateID;
				this.GroupMemberID = GroupMemberID;
			}

			public void CopyTo(ref TBL_BillReportUserGroup to)
			{
				to.ID = this.ID;
				to.BillReportTemplateID = this.BillReportTemplateID;
				to.GroupMemberID = this.GroupMemberID;
			}

			public bool IsSame(TBL_BillReportUserGroup x)
			{
				return(
					this.ID == x.ID &&
					this.BillReportTemplateID == x.BillReportTemplateID &&
					this.GroupMemberID == x.GroupMemberID
				);
			}

			public static TBL_BillReportUserGroup ReadRow(DataRow row)
			{
				TBL_BillReportUserGroup record = new TBL_BillReportUserGroup();
				record.ID = get_int_value(row["ID"]);
				record.BillReportTemplateID = get_int_value(row["BillReportTemplateID"]);
				record.GroupMemberID = get_int_value(row["GroupMemberID"]);
				return record;
			}

			public static List<TBL_BillReportUserGroup> ReadTable(DataTable dt)
			{
				List<TBL_BillReportUserGroup> records = new List<TBL_BillReportUserGroup>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_BillReportUserGroup
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_BillReportUserGroup(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, BillReportTemplateID, GroupMemberID
					from BillReportUserGroup
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "BillReportUserGroup.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "BillReportUserGroup.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_BillReportUserGroup data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_BillReportUserGroup.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportUserGroup.ID, BillReportUserGroup.BillReportTemplateID, BillReportUserGroup.GroupMemberID
					from BillReportUserGroup
					where BillReportUserGroup.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "BillReportUserGroup.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, BillReportTemplateID, GroupMemberID
					from BillReportUserGroup
					", ref dt);
                if (!_ok) m_db.LastError = "BillReportUserGroup.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "BillReportUserGroup.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportUserGroup.ID, BillReportUserGroup.BillReportTemplateID, BillReportUserGroup.GroupMemberID
					from BillReportUserGroup
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "BillReportUserGroup.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select BillReportUserGroup.ID, BillReportUserGroup.BillReportTemplateID, BillReportUserGroup.GroupMemberID
					from BillReportUserGroup
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "BillReportUserGroup.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int BillReportTemplateID,
				int GroupMemberID
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into BillReportUserGroup(
						BillReportTemplateID,
						GroupMemberID
						)
					values(
						@BillReportTemplateID,
						@GroupMemberID
						)
					", BillReportTemplateID, GroupMemberID);
                if (!_ok) m_db.LastError = "BillReportUserGroup.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int BillReportTemplateID,
				int GroupMemberID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportUserGroup where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillReportUserGroup.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportUserGroup.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update BillReportUserGroup
					set
						BillReportTemplateID = @BillReportTemplateID,
						GroupMemberID = @GroupMemberID
					where ID=@ID
					",
					BillReportTemplateID,
					GroupMemberID,
					ID
				);
                if (!_ok) m_db.LastError = "BillReportUserGroup.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from BillReportUserGroup where ID=@ID", ref count, ID))
				{
					m_db.LastError = "BillReportUserGroup.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "BillReportUserGroup.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from BillReportUserGroup where ID=@ID", ID);
                if (!_ok) m_db.LastError = "BillReportUserGroup.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ChangeRequest
		//**********************************************************
		//  ChangeRequest
		//**********************************************************
        CMD_ChangeRequest m_ChangeRequest = null;
        public CMD_ChangeRequest ChangeRequest
        {
            get
            {
				if (m_ChangeRequest == null)
					m_ChangeRequest = new CMD_ChangeRequest(this);
				return m_ChangeRequest;
			}
        }

		[Serializable]
		public class TBL_ChangeRequest
		{
			public int ID { get; set; }
			public string ChangeRequestNo { get; set; }
			public int ChangeRequestTypeID { get; set; }
			public int ChangeRequestStatus { get; set; }
			public string RequestorComment { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDatetime { get; set; }

			public TBL_ChangeRequest()
			{
				this.ID = 0;
				this.ChangeRequestNo = "";
				this.ChangeRequestTypeID = 0;
				this.ChangeRequestStatus = 0;
				this.RequestorComment = "";
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_ChangeRequest(int ID, string ChangeRequestNo, int ChangeRequestTypeID, int ChangeRequestStatus, string RequestorComment, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDatetime)
			{
				this.ID = ID;
				this.ChangeRequestNo = ChangeRequestNo;
				this.ChangeRequestTypeID = ChangeRequestTypeID;
				this.ChangeRequestStatus = ChangeRequestStatus;
				this.RequestorComment = RequestorComment;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDatetime = ModifiedDatetime;
			}

			public void CopyTo(ref TBL_ChangeRequest to)
			{
				to.ID = this.ID;
				to.ChangeRequestNo = this.ChangeRequestNo;
				to.ChangeRequestTypeID = this.ChangeRequestTypeID;
				to.ChangeRequestStatus = this.ChangeRequestStatus;
				to.RequestorComment = this.RequestorComment;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDatetime = this.ModifiedDatetime;
			}

			public bool IsSame(TBL_ChangeRequest x)
			{
				return(
					this.ID == x.ID &&
					this.ChangeRequestNo == x.ChangeRequestNo &&
					this.ChangeRequestTypeID == x.ChangeRequestTypeID &&
					this.ChangeRequestStatus == x.ChangeRequestStatus &&
					this.RequestorComment == x.RequestorComment &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDatetime == x.ModifiedDatetime
				);
			}

			public static TBL_ChangeRequest ReadRow(DataRow row)
			{
				TBL_ChangeRequest record = new TBL_ChangeRequest();
				record.ID = get_int_value(row["ID"]);
				record.ChangeRequestNo = get_string_value(row["ChangeRequestNo"]);
				record.ChangeRequestTypeID = get_int_value(row["ChangeRequestTypeID"]);
				record.ChangeRequestStatus = get_int_value(row["ChangeRequestStatus"]);
				record.RequestorComment = get_string_value(row["RequestorComment"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDatetime = get_DateTime_value(row["ModifiedDatetime"]);
				return record;
			}

			public static List<TBL_ChangeRequest> ReadTable(DataTable dt)
			{
				List<TBL_ChangeRequest> records = new List<TBL_ChangeRequest>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ChangeRequest
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ChangeRequest(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ChangeRequestNo, ChangeRequestTypeID, ChangeRequestStatus, RequestorComment, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from ChangeRequest
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ChangeRequest data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ChangeRequest.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequest.ID, ChangeRequest.ChangeRequestNo, ChangeRequest.ChangeRequestTypeID, ChangeRequest.ChangeRequestStatus, ChangeRequest.RequestorComment, ChangeRequest.CreatedBy, ChangeRequest.CreatedDatetime, ChangeRequest.ModifiedBy, ChangeRequest.ModifiedDatetime
					from ChangeRequest
					where ChangeRequest.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ChangeRequest.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ChangeRequestNo, ChangeRequestTypeID, ChangeRequestStatus, RequestorComment, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from ChangeRequest
					", ref dt);
                if (!_ok) m_db.LastError = "ChangeRequest.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequest.ID, ChangeRequest.ChangeRequestNo, ChangeRequest.ChangeRequestTypeID, ChangeRequest.ChangeRequestStatus, ChangeRequest.RequestorComment, ChangeRequest.CreatedBy, ChangeRequest.CreatedDatetime, ChangeRequest.ModifiedBy, ChangeRequest.ModifiedDatetime
					from ChangeRequest
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequest.ID, ChangeRequest.ChangeRequestNo, ChangeRequest.ChangeRequestTypeID, ChangeRequest.ChangeRequestStatus, ChangeRequest.RequestorComment, ChangeRequest.CreatedBy, ChangeRequest.CreatedDatetime, ChangeRequest.ModifiedBy, ChangeRequest.ModifiedDatetime
					from ChangeRequest
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ChangeRequest.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string ChangeRequestNo,
				int ChangeRequestTypeID,
				int ChangeRequestStatus,
				string RequestorComment,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into ChangeRequest(
						ChangeRequestNo,
						ChangeRequestTypeID,
						ChangeRequestStatus,
						RequestorComment,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDatetime
						)
					values(
						@ChangeRequestNo,
						@ChangeRequestTypeID,
						@ChangeRequestStatus,
						@RequestorComment,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDatetime
						)
					", ChangeRequestNo, ChangeRequestTypeID, ChangeRequestStatus, RequestorComment, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime);
                if (!_ok) m_db.LastError = "ChangeRequest.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string ChangeRequestNo,
				int ChangeRequestTypeID,
				int ChangeRequestStatus,
				string RequestorComment,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequest.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequest.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ChangeRequest
					set
						ChangeRequestNo = @ChangeRequestNo,
						ChangeRequestTypeID = @ChangeRequestTypeID,
						ChangeRequestStatus = @ChangeRequestStatus,
						RequestorComment = @RequestorComment,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDatetime = @ModifiedDatetime
					where ID=@ID
					",
					ChangeRequestNo,
					ChangeRequestTypeID,
					ChangeRequestStatus,
					RequestorComment,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDatetime,
					ID
				);
                if (!_ok) m_db.LastError = "ChangeRequest.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequest.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequest.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ChangeRequest where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ChangeRequest.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ChangeRequestRoleGroup
		//**********************************************************
		//  ChangeRequestRoleGroup
		//**********************************************************
        CMD_ChangeRequestRoleGroup m_ChangeRequestRoleGroup = null;
        public CMD_ChangeRequestRoleGroup ChangeRequestRoleGroup
        {
            get
            {
				if (m_ChangeRequestRoleGroup == null)
					m_ChangeRequestRoleGroup = new CMD_ChangeRequestRoleGroup(this);
				return m_ChangeRequestRoleGroup;
			}
        }

		[Serializable]
		public class TBL_ChangeRequestRoleGroup
		{
			public int ID { get; set; }
			public int ChangeRequestRoleID { get; set; }
			public int GroupMemberID { get; set; }
			public DateTime CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDatetime { get; set; }

			public TBL_ChangeRequestRoleGroup()
			{
				this.ID = 0;
				this.ChangeRequestRoleID = 0;
				this.GroupMemberID = 0;
				this.CreatedBy = Convert.ToDateTime("1900-01-01 00:00:00");
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_ChangeRequestRoleGroup(int ID, int ChangeRequestRoleID, int GroupMemberID, DateTime CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDatetime)
			{
				this.ID = ID;
				this.ChangeRequestRoleID = ChangeRequestRoleID;
				this.GroupMemberID = GroupMemberID;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDatetime = ModifiedDatetime;
			}

			public void CopyTo(ref TBL_ChangeRequestRoleGroup to)
			{
				to.ID = this.ID;
				to.ChangeRequestRoleID = this.ChangeRequestRoleID;
				to.GroupMemberID = this.GroupMemberID;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDatetime = this.ModifiedDatetime;
			}

			public bool IsSame(TBL_ChangeRequestRoleGroup x)
			{
				return(
					this.ID == x.ID &&
					this.ChangeRequestRoleID == x.ChangeRequestRoleID &&
					this.GroupMemberID == x.GroupMemberID &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDatetime == x.ModifiedDatetime
				);
			}

			public static TBL_ChangeRequestRoleGroup ReadRow(DataRow row)
			{
				TBL_ChangeRequestRoleGroup record = new TBL_ChangeRequestRoleGroup();
				record.ID = get_int_value(row["ID"]);
				record.ChangeRequestRoleID = get_int_value(row["ChangeRequestRoleID"]);
				record.GroupMemberID = get_int_value(row["GroupMemberID"]);
				record.CreatedBy = get_DateTime_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDatetime = get_DateTime_value(row["ModifiedDatetime"]);
				return record;
			}

			public static List<TBL_ChangeRequestRoleGroup> ReadTable(DataTable dt)
			{
				List<TBL_ChangeRequestRoleGroup> records = new List<TBL_ChangeRequestRoleGroup>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ChangeRequestRoleGroup
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ChangeRequestRoleGroup(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ChangeRequestRoleID, GroupMemberID, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from ChangeRequestRoleGroup
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ChangeRequestRoleGroup.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ChangeRequestRoleGroup.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ChangeRequestRoleGroup data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ChangeRequestRoleGroup.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestRoleGroup.ID, ChangeRequestRoleGroup.ChangeRequestRoleID, ChangeRequestRoleGroup.GroupMemberID, ChangeRequestRoleGroup.CreatedBy, ChangeRequestRoleGroup.CreatedDatetime, ChangeRequestRoleGroup.ModifiedBy, ChangeRequestRoleGroup.ModifiedDatetime
					from ChangeRequestRoleGroup
					where ChangeRequestRoleGroup.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ChangeRequestRoleID, GroupMemberID, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from ChangeRequestRoleGroup
					", ref dt);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestRoleGroup.ID, ChangeRequestRoleGroup.ChangeRequestRoleID, ChangeRequestRoleGroup.GroupMemberID, ChangeRequestRoleGroup.CreatedBy, ChangeRequestRoleGroup.CreatedDatetime, ChangeRequestRoleGroup.ModifiedBy, ChangeRequestRoleGroup.ModifiedDatetime
					from ChangeRequestRoleGroup
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestRoleGroup.ID, ChangeRequestRoleGroup.ChangeRequestRoleID, ChangeRequestRoleGroup.GroupMemberID, ChangeRequestRoleGroup.CreatedBy, ChangeRequestRoleGroup.CreatedDatetime, ChangeRequestRoleGroup.ModifiedBy, ChangeRequestRoleGroup.ModifiedDatetime
					from ChangeRequestRoleGroup
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ChangeRequestRoleID,
				int GroupMemberID,
				DateTime CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into ChangeRequestRoleGroup(
						ChangeRequestRoleID,
						GroupMemberID,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDatetime
						)
					values(
						@ChangeRequestRoleID,
						@GroupMemberID,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDatetime
						)
					", ChangeRequestRoleID, GroupMemberID, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int ChangeRequestRoleID,
				int GroupMemberID,
				DateTime CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestRoleGroup where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequestRoleGroup.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestRoleGroup.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ChangeRequestRoleGroup
					set
						ChangeRequestRoleID = @ChangeRequestRoleID,
						GroupMemberID = @GroupMemberID,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDatetime = @ModifiedDatetime
					where ID=@ID
					",
					ChangeRequestRoleID,
					GroupMemberID,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDatetime,
					ID
				);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestRoleGroup where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequestRoleGroup.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestRoleGroup.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ChangeRequestRoleGroup where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ChangeRequestRoleGroup.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ChangeRequestStatus
		//**********************************************************
		//  ChangeRequestStatus
		//**********************************************************
        CMD_ChangeRequestStatus m_ChangeRequestStatus = null;
        public CMD_ChangeRequestStatus ChangeRequestStatus
        {
            get
            {
				if (m_ChangeRequestStatus == null)
					m_ChangeRequestStatus = new CMD_ChangeRequestStatus(this);
				return m_ChangeRequestStatus;
			}
        }

		[Serializable]
		public class TBL_ChangeRequestStatus
		{
			public int ID { get; set; }
			public string StatusName { get; set; }

			public TBL_ChangeRequestStatus()
			{
				this.ID = 0;
				this.StatusName = "";
			}

			public TBL_ChangeRequestStatus(int ID, string StatusName)
			{
				this.ID = ID;
				this.StatusName = StatusName;
			}

			public void CopyTo(ref TBL_ChangeRequestStatus to)
			{
				to.ID = this.ID;
				to.StatusName = this.StatusName;
			}

			public bool IsSame(TBL_ChangeRequestStatus x)
			{
				return(
					this.ID == x.ID &&
					this.StatusName == x.StatusName
				);
			}

			public static TBL_ChangeRequestStatus ReadRow(DataRow row)
			{
				TBL_ChangeRequestStatus record = new TBL_ChangeRequestStatus();
				record.ID = get_int_value(row["ID"]);
				record.StatusName = get_string_value(row["StatusName"]);
				return record;
			}

			public static List<TBL_ChangeRequestStatus> ReadTable(DataTable dt)
			{
				List<TBL_ChangeRequestStatus> records = new List<TBL_ChangeRequestStatus>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ChangeRequestStatus
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ChangeRequestStatus(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, StatusName
					from ChangeRequestStatus
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ChangeRequestStatus.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ChangeRequestStatus.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ChangeRequestStatus data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ChangeRequestStatus.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestStatus.ID, ChangeRequestStatus.StatusName
					from ChangeRequestStatus
					where ChangeRequestStatus.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, StatusName
					from ChangeRequestStatus
					", ref dt);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ChangeRequestStatus.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestStatus.ID, ChangeRequestStatus.StatusName
					from ChangeRequestStatus
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestStatus.ID, ChangeRequestStatus.StatusName
					from ChangeRequestStatus
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ID,
				string StatusName
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestStatus where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequestStatus.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestStatus.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into ChangeRequestStatus(
						ID,
						StatusName
						)
					values(
						@ID,
						@StatusName
						)
					", ID, StatusName);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int _old_ID,
				int _new_ID,
				string StatusName
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestStatus where ID=@_old_ID", ref count, _old_ID))
				{
					m_db.LastError = "ChangeRequestStatus.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestStatus.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ChangeRequestStatus
					set
						ID = @_new_ID,
						StatusName = @StatusName
					where ID=@_old_ID
					",
					_new_ID,
					StatusName,
					_old_ID
				);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestStatus where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequestStatus.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestStatus.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ChangeRequestStatus where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ChangeRequestStatus.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ChangeRequestType
		//**********************************************************
		//  ChangeRequestType
		//**********************************************************
        CMD_ChangeRequestType m_ChangeRequestType = null;
        public CMD_ChangeRequestType ChangeRequestType
        {
            get
            {
				if (m_ChangeRequestType == null)
					m_ChangeRequestType = new CMD_ChangeRequestType(this);
				return m_ChangeRequestType;
			}
        }

		[Serializable]
		public class TBL_ChangeRequestType
		{
			public int ID { get; set; }
			public string ChangeRequestType { get; set; }

			public TBL_ChangeRequestType()
			{
				this.ID = 0;
				this.ChangeRequestType = "";
			}

			public TBL_ChangeRequestType(int ID, string ChangeRequestType)
			{
				this.ID = ID;
				this.ChangeRequestType = ChangeRequestType;
			}

			public void CopyTo(ref TBL_ChangeRequestType to)
			{
				to.ID = this.ID;
				to.ChangeRequestType = this.ChangeRequestType;
			}

			public bool IsSame(TBL_ChangeRequestType x)
			{
				return(
					this.ID == x.ID &&
					this.ChangeRequestType == x.ChangeRequestType
				);
			}

			public static TBL_ChangeRequestType ReadRow(DataRow row)
			{
				TBL_ChangeRequestType record = new TBL_ChangeRequestType();
				record.ID = get_int_value(row["ID"]);
				record.ChangeRequestType = get_string_value(row["ChangeRequestType"]);
				return record;
			}

			public static List<TBL_ChangeRequestType> ReadTable(DataTable dt)
			{
				List<TBL_ChangeRequestType> records = new List<TBL_ChangeRequestType>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ChangeRequestType
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ChangeRequestType(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ChangeRequestType
					from ChangeRequestType
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ChangeRequestType.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ChangeRequestType.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ChangeRequestType data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ChangeRequestType.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestType.ID, ChangeRequestType.ChangeRequestType
					from ChangeRequestType
					where ChangeRequestType.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ChangeRequestType.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ChangeRequestType
					from ChangeRequestType
					", ref dt);
                if (!_ok) m_db.LastError = "ChangeRequestType.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ChangeRequestType.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestType.ID, ChangeRequestType.ChangeRequestType
					from ChangeRequestType
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ChangeRequestType.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ChangeRequestType.ID, ChangeRequestType.ChangeRequestType
					from ChangeRequestType
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ChangeRequestType.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ID,
				string ChangeRequestType
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestType where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequestType.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestType.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into ChangeRequestType(
						ID,
						ChangeRequestType
						)
					values(
						@ID,
						@ChangeRequestType
						)
					", ID, ChangeRequestType);
                if (!_ok) m_db.LastError = "ChangeRequestType.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int _old_ID,
				int _new_ID,
				string ChangeRequestType
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestType where ID=@_old_ID", ref count, _old_ID))
				{
					m_db.LastError = "ChangeRequestType.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestType.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ChangeRequestType
					set
						ID = @_new_ID,
						ChangeRequestType = @ChangeRequestType
					where ID=@_old_ID
					",
					_new_ID,
					ChangeRequestType,
					_old_ID
				);
                if (!_ok) m_db.LastError = "ChangeRequestType.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ChangeRequestType where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ChangeRequestType.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ChangeRequestType.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ChangeRequestType where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ChangeRequestType.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region Configuration
		//**********************************************************
		//  Configuration
		//**********************************************************
        CMD_Configuration m_Configuration = null;
        public CMD_Configuration Configuration
        {
            get
            {
				if (m_Configuration == null)
					m_Configuration = new CMD_Configuration(this);
				return m_Configuration;
			}
        }

		[Serializable]
		public class TBL_Configuration
		{
			public int ID { get; set; }
			public string ConfigurationName { get; set; }
			public string ConfigurationValue { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDatetime { get; set; }

			public TBL_Configuration()
			{
				this.ID = 0;
				this.ConfigurationName = "";
				this.ConfigurationValue = "";
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_Configuration(int ID, string ConfigurationName, string ConfigurationValue, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDatetime)
			{
				this.ID = ID;
				this.ConfigurationName = ConfigurationName;
				this.ConfigurationValue = ConfigurationValue;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDatetime = ModifiedDatetime;
			}

			public void CopyTo(ref TBL_Configuration to)
			{
				to.ID = this.ID;
				to.ConfigurationName = this.ConfigurationName;
				to.ConfigurationValue = this.ConfigurationValue;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDatetime = this.ModifiedDatetime;
			}

			public bool IsSame(TBL_Configuration x)
			{
				return(
					this.ID == x.ID &&
					this.ConfigurationName == x.ConfigurationName &&
					this.ConfigurationValue == x.ConfigurationValue &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDatetime == x.ModifiedDatetime
				);
			}

			public static TBL_Configuration ReadRow(DataRow row)
			{
				TBL_Configuration record = new TBL_Configuration();
				record.ID = get_int_value(row["ID"]);
				record.ConfigurationName = get_string_value(row["ConfigurationName"]);
				record.ConfigurationValue = get_string_value(row["ConfigurationValue"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDatetime = get_DateTime_value(row["ModifiedDatetime"]);
				return record;
			}

			public static List<TBL_Configuration> ReadTable(DataTable dt)
			{
				List<TBL_Configuration> records = new List<TBL_Configuration>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_Configuration
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_Configuration(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ConfigurationName, ConfigurationValue, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from Configuration
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "Configuration.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "Configuration.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_Configuration data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_Configuration.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Configuration.ID, Configuration.ConfigurationName, Configuration.ConfigurationValue, Configuration.CreatedBy, Configuration.CreatedDatetime, Configuration.ModifiedBy, Configuration.ModifiedDatetime
					from Configuration
					where Configuration.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "Configuration.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ConfigurationName, ConfigurationValue, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from Configuration
					", ref dt);
                if (!_ok) m_db.LastError = "Configuration.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "Configuration.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Configuration.ID, Configuration.ConfigurationName, Configuration.ConfigurationValue, Configuration.CreatedBy, Configuration.CreatedDatetime, Configuration.ModifiedBy, Configuration.ModifiedDatetime
					from Configuration
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "Configuration.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Configuration.ID, Configuration.ConfigurationName, Configuration.ConfigurationValue, Configuration.CreatedBy, Configuration.CreatedDatetime, Configuration.ModifiedBy, Configuration.ModifiedDatetime
					from Configuration
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "Configuration.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string ConfigurationName,
				string ConfigurationValue,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into Configuration(
						ConfigurationName,
						ConfigurationValue,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDatetime
						)
					values(
						@ConfigurationName,
						@ConfigurationValue,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDatetime
						)
					", ConfigurationName, ConfigurationValue, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime);
                if (!_ok) m_db.LastError = "Configuration.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string ConfigurationName,
				string ConfigurationValue,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Configuration where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Configuration.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Configuration.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update Configuration
					set
						ConfigurationName = @ConfigurationName,
						ConfigurationValue = @ConfigurationValue,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDatetime = @ModifiedDatetime
					where ID=@ID
					",
					ConfigurationName,
					ConfigurationValue,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDatetime,
					ID
				);
                if (!_ok) m_db.LastError = "Configuration.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Configuration where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Configuration.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Configuration.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from Configuration where ID=@ID", ID);
                if (!_ok) m_db.LastError = "Configuration.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region CostCentresInSite
		//**********************************************************
		//  CostCentresInSite
		//**********************************************************
        CMD_CostCentresInSite m_CostCentresInSite = null;
        public CMD_CostCentresInSite CostCentresInSite
        {
            get
            {
				if (m_CostCentresInSite == null)
					m_CostCentresInSite = new CMD_CostCentresInSite(this);
				return m_CostCentresInSite;
			}
        }

		[Serializable]
		public class TBL_CostCentresInSite
		{
			public int ID { get; set; }
			public int SiteID { get; set; }
			public string CostCentreIDName { get; set; }
			public string CostCentreName { get; set; }
			public int CostCentreStatus { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }

			public TBL_CostCentresInSite()
			{
				this.ID = 0;
				this.SiteID = 0;
				this.CostCentreIDName = "";
				this.CostCentreName = "";
				this.CostCentreStatus = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_CostCentresInSite(int ID, int SiteID, string CostCentreIDName, string CostCentreName, int CostCentreStatus, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime)
			{
				this.ID = ID;
				this.SiteID = SiteID;
				this.CostCentreIDName = CostCentreIDName;
				this.CostCentreName = CostCentreName;
				this.CostCentreStatus = CostCentreStatus;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
			}

			public void CopyTo(ref TBL_CostCentresInSite to)
			{
				to.ID = this.ID;
				to.SiteID = this.SiteID;
				to.CostCentreIDName = this.CostCentreIDName;
				to.CostCentreName = this.CostCentreName;
				to.CostCentreStatus = this.CostCentreStatus;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
			}

			public bool IsSame(TBL_CostCentresInSite x)
			{
				return(
					this.ID == x.ID &&
					this.SiteID == x.SiteID &&
					this.CostCentreIDName == x.CostCentreIDName &&
					this.CostCentreName == x.CostCentreName &&
					this.CostCentreStatus == x.CostCentreStatus &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime
				);
			}

			public static TBL_CostCentresInSite ReadRow(DataRow row)
			{
				TBL_CostCentresInSite record = new TBL_CostCentresInSite();
				record.ID = get_int_value(row["ID"]);
				record.SiteID = get_int_value(row["SiteID"]);
				record.CostCentreIDName = get_string_value(row["CostCentreIDName"]);
				record.CostCentreName = get_string_value(row["CostCentreName"]);
				record.CostCentreStatus = get_int_value(row["CostCentreStatus"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				return record;
			}

			public static List<TBL_CostCentresInSite> ReadTable(DataTable dt)
			{
				List<TBL_CostCentresInSite> records = new List<TBL_CostCentresInSite>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_CostCentresInSite
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_CostCentresInSite(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, SiteID, CostCentreIDName, CostCentreName, CostCentreStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from CostCentresInSite
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "CostCentresInSite.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "CostCentresInSite.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_CostCentresInSite data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_CostCentresInSite.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select CostCentresInSite.ID, CostCentresInSite.SiteID, CostCentresInSite.CostCentreIDName, CostCentresInSite.CostCentreName, CostCentresInSite.CostCentreStatus, CostCentresInSite.CreatedBy, CostCentresInSite.CreatedDatetime, CostCentresInSite.ModifiedBy, CostCentresInSite.ModifiedDateTime
					from CostCentresInSite
					where CostCentresInSite.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "CostCentresInSite.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, SiteID, CostCentreIDName, CostCentreName, CostCentreStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from CostCentresInSite
					", ref dt);
                if (!_ok) m_db.LastError = "CostCentresInSite.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "CostCentresInSite.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select CostCentresInSite.ID, CostCentresInSite.SiteID, CostCentresInSite.CostCentreIDName, CostCentresInSite.CostCentreName, CostCentresInSite.CostCentreStatus, CostCentresInSite.CreatedBy, CostCentresInSite.CreatedDatetime, CostCentresInSite.ModifiedBy, CostCentresInSite.ModifiedDateTime
					from CostCentresInSite
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "CostCentresInSite.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select CostCentresInSite.ID, CostCentresInSite.SiteID, CostCentresInSite.CostCentreIDName, CostCentresInSite.CostCentreName, CostCentresInSite.CostCentreStatus, CostCentresInSite.CreatedBy, CostCentresInSite.CreatedDatetime, CostCentresInSite.ModifiedBy, CostCentresInSite.ModifiedDateTime
					from CostCentresInSite
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "CostCentresInSite.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int SiteID,
				string CostCentreIDName,
				string CostCentreName,
				int CostCentreStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into CostCentresInSite(
						SiteID,
						CostCentreIDName,
						CostCentreName,
						CostCentreStatus,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime
						)
					values(
						@SiteID,
						@CostCentreIDName,
						@CostCentreName,
						@CostCentreStatus,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime
						)
					", SiteID, CostCentreIDName, CostCentreName, CostCentreStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime);
                if (!_ok) m_db.LastError = "CostCentresInSite.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int SiteID,
				string CostCentreIDName,
				string CostCentreName,
				int CostCentreStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from CostCentresInSite where ID=@ID", ref count, ID))
				{
					m_db.LastError = "CostCentresInSite.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "CostCentresInSite.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update CostCentresInSite
					set
						SiteID = @SiteID,
						CostCentreIDName = @CostCentreIDName,
						CostCentreName = @CostCentreName,
						CostCentreStatus = @CostCentreStatus,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime
					where ID=@ID
					",
					SiteID,
					CostCentreIDName,
					CostCentreName,
					CostCentreStatus,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					ID
				);
                if (!_ok) m_db.LastError = "CostCentresInSite.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from CostCentresInSite where ID=@ID", ref count, ID))
				{
					m_db.LastError = "CostCentresInSite.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "CostCentresInSite.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from CostCentresInSite where ID=@ID", ID);
                if (!_ok) m_db.LastError = "CostCentresInSite.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region DetailsInChangeRequest
		//**********************************************************
		//  DetailsInChangeRequest
		//**********************************************************
        CMD_DetailsInChangeRequest m_DetailsInChangeRequest = null;
        public CMD_DetailsInChangeRequest DetailsInChangeRequest
        {
            get
            {
				if (m_DetailsInChangeRequest == null)
					m_DetailsInChangeRequest = new CMD_DetailsInChangeRequest(this);
				return m_DetailsInChangeRequest;
			}
        }

		[Serializable]
		public class TBL_DetailsInChangeRequest
		{
			public int ID { get; set; }
			public int ChangeRequestID { get; set; }
			public int New_CostCentreID { get; set; }
			public DateTime New_EffectiveDate { get; set; }
			public DateTime New_TerminatedDate { get; set; }
			public string New_Email { get; set; }
			public string New_Username { get; set; }
			public string New_AssetID { get; set; }
			public string New_ServiceType { get; set; }
			public string New_Hostname { get; set; }
			public string New_OS { get; set; }
			public int New_Status { get; set; }
			public int Old_CostCentreID { get; set; }
			public DateTime Old_EffectiveDate { get; set; }
			public DateTime Old_TerminatedDate { get; set; }
			public int Old_TerminatedBy { get; set; }
			public int Old_CreatedBy { get; set; }
			public DateTime Old_CreatedDatetime { get; set; }
			public int Old_ModifiedBy { get; set; }
			public DateTime Old_ModifiedDateTime { get; set; }
			public string Old_Email { get; set; }
			public string Old_Username { get; set; }
			public string Old_AssetID { get; set; }
			public string Old_ServiceType { get; set; }
			public string Old_Hostname { get; set; }
			public string Old_OS { get; set; }
			public int Old_Status { get; set; }

			public TBL_DetailsInChangeRequest()
			{
				this.ID = 0;
				this.ChangeRequestID = 0;
				this.New_CostCentreID = 0;
				this.New_EffectiveDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.New_TerminatedDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.New_Email = "";
				this.New_Username = "";
				this.New_AssetID = "";
				this.New_ServiceType = "";
				this.New_Hostname = "";
				this.New_OS = "";
				this.New_Status = 0;
				this.Old_CostCentreID = 0;
				this.Old_EffectiveDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.Old_TerminatedDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.Old_TerminatedBy = 0;
				this.Old_CreatedBy = 0;
				this.Old_CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.Old_ModifiedBy = 0;
				this.Old_ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.Old_Email = "";
				this.Old_Username = "";
				this.Old_AssetID = "";
				this.Old_ServiceType = "";
				this.Old_Hostname = "";
				this.Old_OS = "";
				this.Old_Status = 0;
			}

			public TBL_DetailsInChangeRequest(int ID, int ChangeRequestID, int New_CostCentreID, DateTime New_EffectiveDate, DateTime New_TerminatedDate, string New_Email, string New_Username, string New_AssetID, string New_ServiceType, string New_Hostname, string New_OS, int New_Status, int Old_CostCentreID, DateTime Old_EffectiveDate, DateTime Old_TerminatedDate, int Old_TerminatedBy, int Old_CreatedBy, DateTime Old_CreatedDatetime, int Old_ModifiedBy, DateTime Old_ModifiedDateTime, string Old_Email, string Old_Username, string Old_AssetID, string Old_ServiceType, string Old_Hostname, string Old_OS, int Old_Status)
			{
				this.ID = ID;
				this.ChangeRequestID = ChangeRequestID;
				this.New_CostCentreID = New_CostCentreID;
				this.New_EffectiveDate = New_EffectiveDate;
				this.New_TerminatedDate = New_TerminatedDate;
				this.New_Email = New_Email;
				this.New_Username = New_Username;
				this.New_AssetID = New_AssetID;
				this.New_ServiceType = New_ServiceType;
				this.New_Hostname = New_Hostname;
				this.New_OS = New_OS;
				this.New_Status = New_Status;
				this.Old_CostCentreID = Old_CostCentreID;
				this.Old_EffectiveDate = Old_EffectiveDate;
				this.Old_TerminatedDate = Old_TerminatedDate;
				this.Old_TerminatedBy = Old_TerminatedBy;
				this.Old_CreatedBy = Old_CreatedBy;
				this.Old_CreatedDatetime = Old_CreatedDatetime;
				this.Old_ModifiedBy = Old_ModifiedBy;
				this.Old_ModifiedDateTime = Old_ModifiedDateTime;
				this.Old_Email = Old_Email;
				this.Old_Username = Old_Username;
				this.Old_AssetID = Old_AssetID;
				this.Old_ServiceType = Old_ServiceType;
				this.Old_Hostname = Old_Hostname;
				this.Old_OS = Old_OS;
				this.Old_Status = Old_Status;
			}

			public void CopyTo(ref TBL_DetailsInChangeRequest to)
			{
				to.ID = this.ID;
				to.ChangeRequestID = this.ChangeRequestID;
				to.New_CostCentreID = this.New_CostCentreID;
				to.New_EffectiveDate = this.New_EffectiveDate;
				to.New_TerminatedDate = this.New_TerminatedDate;
				to.New_Email = this.New_Email;
				to.New_Username = this.New_Username;
				to.New_AssetID = this.New_AssetID;
				to.New_ServiceType = this.New_ServiceType;
				to.New_Hostname = this.New_Hostname;
				to.New_OS = this.New_OS;
				to.New_Status = this.New_Status;
				to.Old_CostCentreID = this.Old_CostCentreID;
				to.Old_EffectiveDate = this.Old_EffectiveDate;
				to.Old_TerminatedDate = this.Old_TerminatedDate;
				to.Old_TerminatedBy = this.Old_TerminatedBy;
				to.Old_CreatedBy = this.Old_CreatedBy;
				to.Old_CreatedDatetime = this.Old_CreatedDatetime;
				to.Old_ModifiedBy = this.Old_ModifiedBy;
				to.Old_ModifiedDateTime = this.Old_ModifiedDateTime;
				to.Old_Email = this.Old_Email;
				to.Old_Username = this.Old_Username;
				to.Old_AssetID = this.Old_AssetID;
				to.Old_ServiceType = this.Old_ServiceType;
				to.Old_Hostname = this.Old_Hostname;
				to.Old_OS = this.Old_OS;
				to.Old_Status = this.Old_Status;
			}

			public bool IsSame(TBL_DetailsInChangeRequest x)
			{
				return(
					this.ID == x.ID &&
					this.ChangeRequestID == x.ChangeRequestID &&
					this.New_CostCentreID == x.New_CostCentreID &&
					this.New_EffectiveDate == x.New_EffectiveDate &&
					this.New_TerminatedDate == x.New_TerminatedDate &&
					this.New_Email == x.New_Email &&
					this.New_Username == x.New_Username &&
					this.New_AssetID == x.New_AssetID &&
					this.New_ServiceType == x.New_ServiceType &&
					this.New_Hostname == x.New_Hostname &&
					this.New_OS == x.New_OS &&
					this.New_Status == x.New_Status &&
					this.Old_CostCentreID == x.Old_CostCentreID &&
					this.Old_EffectiveDate == x.Old_EffectiveDate &&
					this.Old_TerminatedDate == x.Old_TerminatedDate &&
					this.Old_TerminatedBy == x.Old_TerminatedBy &&
					this.Old_CreatedBy == x.Old_CreatedBy &&
					this.Old_CreatedDatetime == x.Old_CreatedDatetime &&
					this.Old_ModifiedBy == x.Old_ModifiedBy &&
					this.Old_ModifiedDateTime == x.Old_ModifiedDateTime &&
					this.Old_Email == x.Old_Email &&
					this.Old_Username == x.Old_Username &&
					this.Old_AssetID == x.Old_AssetID &&
					this.Old_ServiceType == x.Old_ServiceType &&
					this.Old_Hostname == x.Old_Hostname &&
					this.Old_OS == x.Old_OS &&
					this.Old_Status == x.Old_Status
				);
			}

			public static TBL_DetailsInChangeRequest ReadRow(DataRow row)
			{
				TBL_DetailsInChangeRequest record = new TBL_DetailsInChangeRequest();
				record.ID = get_int_value(row["ID"]);
				record.ChangeRequestID = get_int_value(row["ChangeRequestID"]);
				record.New_CostCentreID = get_int_value(row["New_CostCentreID"]);
				record.New_EffectiveDate = get_DateTime_value(row["New_EffectiveDate"]);
				record.New_TerminatedDate = get_DateTime_value(row["New_TerminatedDate"]);
				record.New_Email = get_string_value(row["New_Email"]);
				record.New_Username = get_string_value(row["New_Username"]);
				record.New_AssetID = get_string_value(row["New_AssetID"]);
				record.New_ServiceType = get_string_value(row["New_ServiceType"]);
				record.New_Hostname = get_string_value(row["New_Hostname"]);
				record.New_OS = get_string_value(row["New_OS"]);
				record.New_Status = get_int_value(row["New_Status"]);
				record.Old_CostCentreID = get_int_value(row["Old_CostCentreID"]);
				record.Old_EffectiveDate = get_DateTime_value(row["Old_EffectiveDate"]);
				record.Old_TerminatedDate = get_DateTime_value(row["Old_TerminatedDate"]);
				record.Old_TerminatedBy = get_int_value(row["Old_TerminatedBy"]);
				record.Old_CreatedBy = get_int_value(row["Old_CreatedBy"]);
				record.Old_CreatedDatetime = get_DateTime_value(row["Old_CreatedDatetime"]);
				record.Old_ModifiedBy = get_int_value(row["Old_ModifiedBy"]);
				record.Old_ModifiedDateTime = get_DateTime_value(row["Old_ModifiedDateTime"]);
				record.Old_Email = get_string_value(row["Old_Email"]);
				record.Old_Username = get_string_value(row["Old_Username"]);
				record.Old_AssetID = get_string_value(row["Old_AssetID"]);
				record.Old_ServiceType = get_string_value(row["Old_ServiceType"]);
				record.Old_Hostname = get_string_value(row["Old_Hostname"]);
				record.Old_OS = get_string_value(row["Old_OS"]);
				record.Old_Status = get_int_value(row["Old_Status"]);
				return record;
			}

			public static List<TBL_DetailsInChangeRequest> ReadTable(DataTable dt)
			{
				List<TBL_DetailsInChangeRequest> records = new List<TBL_DetailsInChangeRequest>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_DetailsInChangeRequest
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_DetailsInChangeRequest(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ChangeRequestID, New_CostCentreID, New_EffectiveDate, New_TerminatedDate, New_Email, New_Username, New_AssetID, New_ServiceType, New_Hostname, New_OS, New_Status, Old_CostCentreID, Old_EffectiveDate, Old_TerminatedDate, Old_TerminatedBy, Old_CreatedBy, Old_CreatedDatetime, Old_ModifiedBy, Old_ModifiedDateTime, Old_Email, Old_Username, Old_AssetID, Old_ServiceType, Old_Hostname, Old_OS, Old_Status
					from DetailsInChangeRequest
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "DetailsInChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "DetailsInChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_DetailsInChangeRequest data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_DetailsInChangeRequest.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select DetailsInChangeRequest.ID, DetailsInChangeRequest.ChangeRequestID, DetailsInChangeRequest.New_CostCentreID, DetailsInChangeRequest.New_EffectiveDate, DetailsInChangeRequest.New_TerminatedDate, DetailsInChangeRequest.New_Email, DetailsInChangeRequest.New_Username, DetailsInChangeRequest.New_AssetID, DetailsInChangeRequest.New_ServiceType, DetailsInChangeRequest.New_Hostname, DetailsInChangeRequest.New_OS, DetailsInChangeRequest.New_Status, DetailsInChangeRequest.Old_CostCentreID, DetailsInChangeRequest.Old_EffectiveDate, DetailsInChangeRequest.Old_TerminatedDate, DetailsInChangeRequest.Old_TerminatedBy, DetailsInChangeRequest.Old_CreatedBy, DetailsInChangeRequest.Old_CreatedDatetime, DetailsInChangeRequest.Old_ModifiedBy, DetailsInChangeRequest.Old_ModifiedDateTime, DetailsInChangeRequest.Old_Email, DetailsInChangeRequest.Old_Username, DetailsInChangeRequest.Old_AssetID, DetailsInChangeRequest.Old_ServiceType, DetailsInChangeRequest.Old_Hostname, DetailsInChangeRequest.Old_OS, DetailsInChangeRequest.Old_Status
					from DetailsInChangeRequest
					where DetailsInChangeRequest.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ChangeRequestID, New_CostCentreID, New_EffectiveDate, New_TerminatedDate, New_Email, New_Username, New_AssetID, New_ServiceType, New_Hostname, New_OS, New_Status, Old_CostCentreID, Old_EffectiveDate, Old_TerminatedDate, Old_TerminatedBy, Old_CreatedBy, Old_CreatedDatetime, Old_ModifiedBy, Old_ModifiedDateTime, Old_Email, Old_Username, Old_AssetID, Old_ServiceType, Old_Hostname, Old_OS, Old_Status
					from DetailsInChangeRequest
					", ref dt);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "DetailsInChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select DetailsInChangeRequest.ID, DetailsInChangeRequest.ChangeRequestID, DetailsInChangeRequest.New_CostCentreID, DetailsInChangeRequest.New_EffectiveDate, DetailsInChangeRequest.New_TerminatedDate, DetailsInChangeRequest.New_Email, DetailsInChangeRequest.New_Username, DetailsInChangeRequest.New_AssetID, DetailsInChangeRequest.New_ServiceType, DetailsInChangeRequest.New_Hostname, DetailsInChangeRequest.New_OS, DetailsInChangeRequest.New_Status, DetailsInChangeRequest.Old_CostCentreID, DetailsInChangeRequest.Old_EffectiveDate, DetailsInChangeRequest.Old_TerminatedDate, DetailsInChangeRequest.Old_TerminatedBy, DetailsInChangeRequest.Old_CreatedBy, DetailsInChangeRequest.Old_CreatedDatetime, DetailsInChangeRequest.Old_ModifiedBy, DetailsInChangeRequest.Old_ModifiedDateTime, DetailsInChangeRequest.Old_Email, DetailsInChangeRequest.Old_Username, DetailsInChangeRequest.Old_AssetID, DetailsInChangeRequest.Old_ServiceType, DetailsInChangeRequest.Old_Hostname, DetailsInChangeRequest.Old_OS, DetailsInChangeRequest.Old_Status
					from DetailsInChangeRequest
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select DetailsInChangeRequest.ID, DetailsInChangeRequest.ChangeRequestID, DetailsInChangeRequest.New_CostCentreID, DetailsInChangeRequest.New_EffectiveDate, DetailsInChangeRequest.New_TerminatedDate, DetailsInChangeRequest.New_Email, DetailsInChangeRequest.New_Username, DetailsInChangeRequest.New_AssetID, DetailsInChangeRequest.New_ServiceType, DetailsInChangeRequest.New_Hostname, DetailsInChangeRequest.New_OS, DetailsInChangeRequest.New_Status, DetailsInChangeRequest.Old_CostCentreID, DetailsInChangeRequest.Old_EffectiveDate, DetailsInChangeRequest.Old_TerminatedDate, DetailsInChangeRequest.Old_TerminatedBy, DetailsInChangeRequest.Old_CreatedBy, DetailsInChangeRequest.Old_CreatedDatetime, DetailsInChangeRequest.Old_ModifiedBy, DetailsInChangeRequest.Old_ModifiedDateTime, DetailsInChangeRequest.Old_Email, DetailsInChangeRequest.Old_Username, DetailsInChangeRequest.Old_AssetID, DetailsInChangeRequest.Old_ServiceType, DetailsInChangeRequest.Old_Hostname, DetailsInChangeRequest.Old_OS, DetailsInChangeRequest.Old_Status
					from DetailsInChangeRequest
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ChangeRequestID,
				int New_CostCentreID,
				DateTime New_EffectiveDate,
				DateTime New_TerminatedDate,
				string New_Email,
				string New_Username,
				string New_AssetID,
				string New_ServiceType,
				string New_Hostname,
				string New_OS,
				int New_Status,
				int Old_CostCentreID,
				DateTime Old_EffectiveDate,
				DateTime Old_TerminatedDate,
				int Old_TerminatedBy,
				int Old_CreatedBy,
				DateTime Old_CreatedDatetime,
				int Old_ModifiedBy,
				DateTime Old_ModifiedDateTime,
				string Old_Email,
				string Old_Username,
				string Old_AssetID,
				string Old_ServiceType,
				string Old_Hostname,
				string Old_OS,
				int Old_Status
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into DetailsInChangeRequest(
						ChangeRequestID,
						New_CostCentreID,
						New_EffectiveDate,
						New_TerminatedDate,
						New_Email,
						New_Username,
						New_AssetID,
						New_ServiceType,
						New_Hostname,
						New_OS,
						New_Status,
						Old_CostCentreID,
						Old_EffectiveDate,
						Old_TerminatedDate,
						Old_TerminatedBy,
						Old_CreatedBy,
						Old_CreatedDatetime,
						Old_ModifiedBy,
						Old_ModifiedDateTime,
						Old_Email,
						Old_Username,
						Old_AssetID,
						Old_ServiceType,
						Old_Hostname,
						Old_OS,
						Old_Status
						)
					values(
						@ChangeRequestID,
						@New_CostCentreID,
						@New_EffectiveDate,
						@New_TerminatedDate,
						@New_Email,
						@New_Username,
						@New_AssetID,
						@New_ServiceType,
						@New_Hostname,
						@New_OS,
						@New_Status,
						@Old_CostCentreID,
						@Old_EffectiveDate,
						@Old_TerminatedDate,
						@Old_TerminatedBy,
						@Old_CreatedBy,
						@Old_CreatedDatetime,
						@Old_ModifiedBy,
						@Old_ModifiedDateTime,
						@Old_Email,
						@Old_Username,
						@Old_AssetID,
						@Old_ServiceType,
						@Old_Hostname,
						@Old_OS,
						@Old_Status
						)
					", ChangeRequestID, New_CostCentreID, New_EffectiveDate, New_TerminatedDate, New_Email, New_Username, New_AssetID, New_ServiceType, New_Hostname, New_OS, New_Status, Old_CostCentreID, Old_EffectiveDate, Old_TerminatedDate, Old_TerminatedBy, Old_CreatedBy, Old_CreatedDatetime, Old_ModifiedBy, Old_ModifiedDateTime, Old_Email, Old_Username, Old_AssetID, Old_ServiceType, Old_Hostname, Old_OS, Old_Status);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int ChangeRequestID,
				int New_CostCentreID,
				DateTime New_EffectiveDate,
				DateTime New_TerminatedDate,
				string New_Email,
				string New_Username,
				string New_AssetID,
				string New_ServiceType,
				string New_Hostname,
				string New_OS,
				int New_Status,
				int Old_CostCentreID,
				DateTime Old_EffectiveDate,
				DateTime Old_TerminatedDate,
				int Old_TerminatedBy,
				int Old_CreatedBy,
				DateTime Old_CreatedDatetime,
				int Old_ModifiedBy,
				DateTime Old_ModifiedDateTime,
				string Old_Email,
				string Old_Username,
				string Old_AssetID,
				string Old_ServiceType,
				string Old_Hostname,
				string Old_OS,
				int Old_Status
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from DetailsInChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "DetailsInChangeRequest.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "DetailsInChangeRequest.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update DetailsInChangeRequest
					set
						ChangeRequestID = @ChangeRequestID,
						New_CostCentreID = @New_CostCentreID,
						New_EffectiveDate = @New_EffectiveDate,
						New_TerminatedDate = @New_TerminatedDate,
						New_Email = @New_Email,
						New_Username = @New_Username,
						New_AssetID = @New_AssetID,
						New_ServiceType = @New_ServiceType,
						New_Hostname = @New_Hostname,
						New_OS = @New_OS,
						New_Status = @New_Status,
						Old_CostCentreID = @Old_CostCentreID,
						Old_EffectiveDate = @Old_EffectiveDate,
						Old_TerminatedDate = @Old_TerminatedDate,
						Old_TerminatedBy = @Old_TerminatedBy,
						Old_CreatedBy = @Old_CreatedBy,
						Old_CreatedDatetime = @Old_CreatedDatetime,
						Old_ModifiedBy = @Old_ModifiedBy,
						Old_ModifiedDateTime = @Old_ModifiedDateTime,
						Old_Email = @Old_Email,
						Old_Username = @Old_Username,
						Old_AssetID = @Old_AssetID,
						Old_ServiceType = @Old_ServiceType,
						Old_Hostname = @Old_Hostname,
						Old_OS = @Old_OS,
						Old_Status = @Old_Status
					where ID=@ID
					",
					ChangeRequestID,
					New_CostCentreID,
					New_EffectiveDate,
					New_TerminatedDate,
					New_Email,
					New_Username,
					New_AssetID,
					New_ServiceType,
					New_Hostname,
					New_OS,
					New_Status,
					Old_CostCentreID,
					Old_EffectiveDate,
					Old_TerminatedDate,
					Old_TerminatedBy,
					Old_CreatedBy,
					Old_CreatedDatetime,
					Old_ModifiedBy,
					Old_ModifiedDateTime,
					Old_Email,
					Old_Username,
					Old_AssetID,
					Old_ServiceType,
					Old_Hostname,
					Old_OS,
					Old_Status,
					ID
				);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from DetailsInChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "DetailsInChangeRequest.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "DetailsInChangeRequest.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from DetailsInChangeRequest where ID=@ID", ID);
                if (!_ok) m_db.LastError = "DetailsInChangeRequest.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region DomainsInSite
		//**********************************************************
		//  DomainsInSite
		//**********************************************************
        CMD_DomainsInSite m_DomainsInSite = null;
        public CMD_DomainsInSite DomainsInSite
        {
            get
            {
				if (m_DomainsInSite == null)
					m_DomainsInSite = new CMD_DomainsInSite(this);
				return m_DomainsInSite;
			}
        }

		[Serializable]
		public class TBL_DomainsInSite
		{
			public int ID { get; set; }
			public int SiteID { get; set; }
			public string DomainName { get; set; }
			public int DomainStatus { get; set; }

			public TBL_DomainsInSite()
			{
				this.ID = 0;
				this.SiteID = 0;
				this.DomainName = "";
				this.DomainStatus = 0;
			}

			public TBL_DomainsInSite(int ID, int SiteID, string DomainName, int DomainStatus)
			{
				this.ID = ID;
				this.SiteID = SiteID;
				this.DomainName = DomainName;
				this.DomainStatus = DomainStatus;
			}

			public void CopyTo(ref TBL_DomainsInSite to)
			{
				to.ID = this.ID;
				to.SiteID = this.SiteID;
				to.DomainName = this.DomainName;
				to.DomainStatus = this.DomainStatus;
			}

			public bool IsSame(TBL_DomainsInSite x)
			{
				return(
					this.ID == x.ID &&
					this.SiteID == x.SiteID &&
					this.DomainName == x.DomainName &&
					this.DomainStatus == x.DomainStatus
				);
			}

			public static TBL_DomainsInSite ReadRow(DataRow row)
			{
				TBL_DomainsInSite record = new TBL_DomainsInSite();
				record.ID = get_int_value(row["ID"]);
				record.SiteID = get_int_value(row["SiteID"]);
				record.DomainName = get_string_value(row["DomainName"]);
				record.DomainStatus = get_int_value(row["DomainStatus"]);
				return record;
			}

			public static List<TBL_DomainsInSite> ReadTable(DataTable dt)
			{
				List<TBL_DomainsInSite> records = new List<TBL_DomainsInSite>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_DomainsInSite
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_DomainsInSite(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, SiteID, DomainName, DomainStatus
					from DomainsInSite
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "DomainsInSite.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "DomainsInSite.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_DomainsInSite data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_DomainsInSite.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select DomainsInSite.ID, DomainsInSite.SiteID, DomainsInSite.DomainName, DomainsInSite.DomainStatus
					from DomainsInSite
					where DomainsInSite.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "DomainsInSite.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, SiteID, DomainName, DomainStatus
					from DomainsInSite
					", ref dt);
                if (!_ok) m_db.LastError = "DomainsInSite.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "DomainsInSite.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select DomainsInSite.ID, DomainsInSite.SiteID, DomainsInSite.DomainName, DomainsInSite.DomainStatus
					from DomainsInSite
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "DomainsInSite.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select DomainsInSite.ID, DomainsInSite.SiteID, DomainsInSite.DomainName, DomainsInSite.DomainStatus
					from DomainsInSite
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "DomainsInSite.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int SiteID,
				string DomainName,
				int DomainStatus
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into DomainsInSite(
						SiteID,
						DomainName,
						DomainStatus
						)
					values(
						@SiteID,
						@DomainName,
						@DomainStatus
						)
					", SiteID, DomainName, DomainStatus);
                if (!_ok) m_db.LastError = "DomainsInSite.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int SiteID,
				string DomainName,
				int DomainStatus
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from DomainsInSite where ID=@ID", ref count, ID))
				{
					m_db.LastError = "DomainsInSite.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "DomainsInSite.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update DomainsInSite
					set
						SiteID = @SiteID,
						DomainName = @DomainName,
						DomainStatus = @DomainStatus
					where ID=@ID
					",
					SiteID,
					DomainName,
					DomainStatus,
					ID
				);
                if (!_ok) m_db.LastError = "DomainsInSite.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from DomainsInSite where ID=@ID", ref count, ID))
				{
					m_db.LastError = "DomainsInSite.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "DomainsInSite.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from DomainsInSite where ID=@ID", ID);
                if (!_ok) m_db.LastError = "DomainsInSite.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region GeneralStatus
		//**********************************************************
		//  GeneralStatus
		//**********************************************************
        CMD_GeneralStatus m_GeneralStatus = null;
        public CMD_GeneralStatus GeneralStatus
        {
            get
            {
				if (m_GeneralStatus == null)
					m_GeneralStatus = new CMD_GeneralStatus(this);
				return m_GeneralStatus;
			}
        }

		[Serializable]
		public class TBL_GeneralStatus
		{
			public int ID { get; set; }
			public string Status0 { get; set; }

			public TBL_GeneralStatus()
			{
				this.ID = 0;
				this.Status0 = "";
			}

			public TBL_GeneralStatus(int ID, string Status0)
			{
				this.ID = ID;
				this.Status0 = Status0;
			}

			public void CopyTo(ref TBL_GeneralStatus to)
			{
				to.ID = this.ID;
				to.Status0 = this.Status0;
			}

			public bool IsSame(TBL_GeneralStatus x)
			{
				return(
					this.ID == x.ID &&
					this.Status0 == x.Status0
				);
			}

			public static TBL_GeneralStatus ReadRow(DataRow row)
			{
				TBL_GeneralStatus record = new TBL_GeneralStatus();
				record.ID = get_int_value(row["ID"]);
				record.Status0 = get_string_value(row["Status0"]);
				return record;
			}

			public static List<TBL_GeneralStatus> ReadTable(DataTable dt)
			{
				List<TBL_GeneralStatus> records = new List<TBL_GeneralStatus>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_GeneralStatus
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_GeneralStatus(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, Status0
					from GeneralStatus
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "GeneralStatus.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "GeneralStatus.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_GeneralStatus data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_GeneralStatus.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GeneralStatus.ID, GeneralStatus.Status0
					from GeneralStatus
					where GeneralStatus.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "GeneralStatus.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, Status0
					from GeneralStatus
					", ref dt);
                if (!_ok) m_db.LastError = "GeneralStatus.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "GeneralStatus.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GeneralStatus.ID, GeneralStatus.Status0
					from GeneralStatus
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "GeneralStatus.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GeneralStatus.ID, GeneralStatus.Status0
					from GeneralStatus
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "GeneralStatus.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string Status0
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into GeneralStatus(
						Status0
						)
					values(
						@Status0
						)
					", Status0);
                if (!_ok) m_db.LastError = "GeneralStatus.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string Status0
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GeneralStatus where ID=@ID", ref count, ID))
				{
					m_db.LastError = "GeneralStatus.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GeneralStatus.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update GeneralStatus
					set
						Status0 = @Status0
					where ID=@ID
					",
					Status0,
					ID
				);
                if (!_ok) m_db.LastError = "GeneralStatus.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GeneralStatus where ID=@ID", ref count, ID))
				{
					m_db.LastError = "GeneralStatus.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GeneralStatus.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from GeneralStatus where ID=@ID", ID);
                if (!_ok) m_db.LastError = "GeneralStatus.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region GroupMember
		//**********************************************************
		//  GroupMember
		//**********************************************************
        CMD_GroupMember m_GroupMember = null;
        public CMD_GroupMember GroupMember
        {
            get
            {
				if (m_GroupMember == null)
					m_GroupMember = new CMD_GroupMember(this);
				return m_GroupMember;
			}
        }

		[Serializable]
		public class TBL_GroupMember
		{
			public int GroupID { get; set; }
			public string GroupName { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }
			public int GroupStatus { get; set; }

			public TBL_GroupMember()
			{
				this.GroupID = 0;
				this.GroupName = "";
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.GroupStatus = 0;
			}

			public TBL_GroupMember(int GroupID, string GroupName, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime, int GroupStatus)
			{
				this.GroupID = GroupID;
				this.GroupName = GroupName;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
				this.GroupStatus = GroupStatus;
			}

			public void CopyTo(ref TBL_GroupMember to)
			{
				to.GroupID = this.GroupID;
				to.GroupName = this.GroupName;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
				to.GroupStatus = this.GroupStatus;
			}

			public bool IsSame(TBL_GroupMember x)
			{
				return(
					this.GroupID == x.GroupID &&
					this.GroupName == x.GroupName &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime &&
					this.GroupStatus == x.GroupStatus
				);
			}

			public static TBL_GroupMember ReadRow(DataRow row)
			{
				TBL_GroupMember record = new TBL_GroupMember();
				record.GroupID = get_int_value(row["GroupID"]);
				record.GroupName = get_string_value(row["GroupName"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				record.GroupStatus = get_int_value(row["GroupStatus"]);
				return record;
			}

			public static List<TBL_GroupMember> ReadTable(DataTable dt)
			{
				List<TBL_GroupMember> records = new List<TBL_GroupMember>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_GroupMember
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_GroupMember(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select GroupID, GroupName, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, GroupStatus
					from GroupMember
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "GroupMember.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int GroupID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where GroupID=@GroupID"
					, GroupID))
                {
                    m_db.LastError = "GroupMember.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int GroupID,
				ref TBL_GroupMember data
			)
			{
                DataTable dt = null;
				if (!select(
				        GroupID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_GroupMember.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int GroupID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMember.GroupID, GroupMember.GroupName, GroupMember.CreatedBy, GroupMember.CreatedDatetime, GroupMember.ModifiedBy, GroupMember.ModifiedDateTime, GroupMember.GroupStatus
					from GroupMember
					where GroupMember.GroupID=@GroupID
					", ref dt, GroupID);
                if (!_ok) m_db.LastError = "GroupMember.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupID, GroupName, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, GroupStatus
					from GroupMember
					", ref dt);
                if (!_ok) m_db.LastError = "GroupMember.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "GroupMember.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMember.GroupID, GroupMember.GroupName, GroupMember.CreatedBy, GroupMember.CreatedDatetime, GroupMember.ModifiedBy, GroupMember.ModifiedDateTime, GroupMember.GroupStatus
					from GroupMember
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "GroupMember.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMember.GroupID, GroupMember.GroupName, GroupMember.CreatedBy, GroupMember.CreatedDatetime, GroupMember.ModifiedBy, GroupMember.ModifiedDateTime, GroupMember.GroupStatus
					from GroupMember
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "GroupMember.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int GroupID,
				string GroupName,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				int GroupStatus
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GroupMember where GroupID=@GroupID", ref count, GroupID))
				{
					m_db.LastError = "GroupMember.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GroupMember.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into GroupMember(
						GroupID,
						GroupName,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime,
						GroupStatus
						)
					values(
						@GroupID,
						@GroupName,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime,
						@GroupStatus
						)
					", GroupID, GroupName, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, GroupStatus);
                if (!_ok) m_db.LastError = "GroupMember.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int _old_GroupID,
				int _new_GroupID,
				string GroupName,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				int GroupStatus
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GroupMember where GroupID=@_old_GroupID", ref count, _old_GroupID))
				{
					m_db.LastError = "GroupMember.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GroupMember.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update GroupMember
					set
						GroupID = @_new_GroupID,
						GroupName = @GroupName,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime,
						GroupStatus = @GroupStatus
					where GroupID=@_old_GroupID
					",
					_new_GroupID,
					GroupName,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					GroupStatus,
					_old_GroupID
				);
                if (!_ok) m_db.LastError = "GroupMember.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int GroupID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GroupMember where GroupID=@GroupID", ref count, GroupID))
				{
					m_db.LastError = "GroupMember.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GroupMember.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from GroupMember where GroupID=@GroupID", GroupID);
                if (!_ok) m_db.LastError = "GroupMember.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region GroupMemberInResourcePermission
		//**********************************************************
		//  GroupMemberInResourcePermission
		//**********************************************************
        CMD_GroupMemberInResourcePermission m_GroupMemberInResourcePermission = null;
        public CMD_GroupMemberInResourcePermission GroupMemberInResourcePermission
        {
            get
            {
				if (m_GroupMemberInResourcePermission == null)
					m_GroupMemberInResourcePermission = new CMD_GroupMemberInResourcePermission(this);
				return m_GroupMemberInResourcePermission;
			}
        }

		[Serializable]
		public class TBL_GroupMemberInResourcePermission
		{
			public int GroupMemberID { get; set; }
			public int ResourceID { get; set; }
			public int Create0 { get; set; }
			public int Read0 { get; set; }
			public int Update0 { get; set; }
			public int Delete0 { get; set; }
			public int Status { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }

			public TBL_GroupMemberInResourcePermission()
			{
				this.GroupMemberID = 0;
				this.ResourceID = 0;
				this.Create0 = 0;
				this.Read0 = 0;
				this.Update0 = 0;
				this.Delete0 = 0;
				this.Status = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_GroupMemberInResourcePermission(int GroupMemberID, int ResourceID, int Create0, int Read0, int Update0, int Delete0, int Status, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime)
			{
				this.GroupMemberID = GroupMemberID;
				this.ResourceID = ResourceID;
				this.Create0 = Create0;
				this.Read0 = Read0;
				this.Update0 = Update0;
				this.Delete0 = Delete0;
				this.Status = Status;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
			}

			public void CopyTo(ref TBL_GroupMemberInResourcePermission to)
			{
				to.GroupMemberID = this.GroupMemberID;
				to.ResourceID = this.ResourceID;
				to.Create0 = this.Create0;
				to.Read0 = this.Read0;
				to.Update0 = this.Update0;
				to.Delete0 = this.Delete0;
				to.Status = this.Status;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
			}

			public bool IsSame(TBL_GroupMemberInResourcePermission x)
			{
				return(
					this.GroupMemberID == x.GroupMemberID &&
					this.ResourceID == x.ResourceID &&
					this.Create0 == x.Create0 &&
					this.Read0 == x.Read0 &&
					this.Update0 == x.Update0 &&
					this.Delete0 == x.Delete0 &&
					this.Status == x.Status &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime
				);
			}

			public static TBL_GroupMemberInResourcePermission ReadRow(DataRow row)
			{
				TBL_GroupMemberInResourcePermission record = new TBL_GroupMemberInResourcePermission();
				record.GroupMemberID = get_int_value(row["GroupMemberID"]);
				record.ResourceID = get_int_value(row["ResourceID"]);
				record.Create0 = get_int_value(row["Create0"]);
				record.Read0 = get_int_value(row["Read0"]);
				record.Update0 = get_int_value(row["Update0"]);
				record.Delete0 = get_int_value(row["Delete0"]);
				record.Status = get_int_value(row["Status"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				return record;
			}

			public static List<TBL_GroupMemberInResourcePermission> ReadTable(DataTable dt)
			{
				List<TBL_GroupMemberInResourcePermission> records = new List<TBL_GroupMemberInResourcePermission>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_GroupMemberInResourcePermission
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_GroupMemberInResourcePermission(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select GroupMemberID, ResourceID, Create0, Read0, Update0, Delete0, Status, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from GroupMemberInResourcePermission
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "GroupMemberInResourcePermission.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int GroupMemberID,
				int ResourceID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where GroupMemberID=@GroupMemberID and ResourceID=@ResourceID"
					, GroupMemberID, ResourceID))
                {
                    m_db.LastError = "GroupMemberInResourcePermission.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int GroupMemberID,
				int ResourceID,
				ref TBL_GroupMemberInResourcePermission data
			)
			{
                DataTable dt = null;
				if (!select(
				        GroupMemberID,
				        ResourceID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_GroupMemberInResourcePermission.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int GroupMemberID,
				int ResourceID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMemberInResourcePermission.GroupMemberID, GroupMemberInResourcePermission.ResourceID, GroupMemberInResourcePermission.Create0, GroupMemberInResourcePermission.Read0, GroupMemberInResourcePermission.Update0, GroupMemberInResourcePermission.Delete0, GroupMemberInResourcePermission.Status, GroupMemberInResourcePermission.CreatedBy, GroupMemberInResourcePermission.CreatedDatetime, GroupMemberInResourcePermission.ModifiedBy, GroupMemberInResourcePermission.ModifiedDateTime
					from GroupMemberInResourcePermission
					where GroupMemberInResourcePermission.GroupMemberID=@GroupMemberID and GroupMemberInResourcePermission.ResourceID=@ResourceID
					", ref dt, GroupMemberID, ResourceID);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMemberID, ResourceID, Create0, Read0, Update0, Delete0, Status, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from GroupMemberInResourcePermission
					", ref dt);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMemberInResourcePermission.GroupMemberID, GroupMemberInResourcePermission.ResourceID, GroupMemberInResourcePermission.Create0, GroupMemberInResourcePermission.Read0, GroupMemberInResourcePermission.Update0, GroupMemberInResourcePermission.Delete0, GroupMemberInResourcePermission.Status, GroupMemberInResourcePermission.CreatedBy, GroupMemberInResourcePermission.CreatedDatetime, GroupMemberInResourcePermission.ModifiedBy, GroupMemberInResourcePermission.ModifiedDateTime
					from GroupMemberInResourcePermission
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select GroupMemberInResourcePermission.GroupMemberID, GroupMemberInResourcePermission.ResourceID, GroupMemberInResourcePermission.Create0, GroupMemberInResourcePermission.Read0, GroupMemberInResourcePermission.Update0, GroupMemberInResourcePermission.Delete0, GroupMemberInResourcePermission.Status, GroupMemberInResourcePermission.CreatedBy, GroupMemberInResourcePermission.CreatedDatetime, GroupMemberInResourcePermission.ModifiedBy, GroupMemberInResourcePermission.ModifiedDateTime
					from GroupMemberInResourcePermission
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int GroupMemberID,
				int ResourceID,
				int Create0,
				int Read0,
				int Update0,
				int Delete0,
				int Status,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GroupMemberInResourcePermission where GroupMemberID=@GroupMemberID and ResourceID=@ResourceID", ref count, GroupMemberID, ResourceID))
				{
					m_db.LastError = "GroupMemberInResourcePermission.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GroupMemberInResourcePermission.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into GroupMemberInResourcePermission(
						GroupMemberID,
						ResourceID,
						Create0,
						Read0,
						Update0,
						Delete0,
						Status,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime
						)
					values(
						@GroupMemberID,
						@ResourceID,
						@Create0,
						@Read0,
						@Update0,
						@Delete0,
						@Status,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime
						)
					", GroupMemberID, ResourceID, Create0, Read0, Update0, Delete0, Status, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int _old_GroupMemberID,
				int _old_ResourceID,
				int _new_GroupMemberID,
				int _new_ResourceID,
				int Create0,
				int Read0,
				int Update0,
				int Delete0,
				int Status,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GroupMemberInResourcePermission where GroupMemberID=@_old_GroupMemberID and ResourceID=@_old_ResourceID", ref count, _old_GroupMemberID, _old_ResourceID))
				{
					m_db.LastError = "GroupMemberInResourcePermission.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GroupMemberInResourcePermission.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update GroupMemberInResourcePermission
					set
						GroupMemberID = @_new_GroupMemberID,
						ResourceID = @_new_ResourceID,
						Create0 = @Create0,
						Read0 = @Read0,
						Update0 = @Update0,
						Delete0 = @Delete0,
						Status = @Status,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime
					where GroupMemberID=@_old_GroupMemberID and ResourceID=@_old_ResourceID
					",
					_new_GroupMemberID,
					_new_ResourceID,
					Create0,
					Read0,
					Update0,
					Delete0,
					Status,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					_old_GroupMemberID,
					_old_ResourceID
				);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int GroupMemberID,
				int ResourceID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from GroupMemberInResourcePermission where GroupMemberID=@GroupMemberID and ResourceID=@ResourceID", ref count, GroupMemberID, ResourceID))
				{
					m_db.LastError = "GroupMemberInResourcePermission.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "GroupMemberInResourcePermission.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from GroupMemberInResourcePermission where GroupMemberID=@GroupMemberID and ResourceID=@ResourceID", GroupMemberID, ResourceID);
                if (!_ok) m_db.LastError = "GroupMemberInResourcePermission.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region Notice
		//**********************************************************
		//  Notice
		//**********************************************************
        CMD_Notice m_Notice = null;
        public CMD_Notice Notice
        {
            get
            {
				if (m_Notice == null)
					m_Notice = new CMD_Notice(this);
				return m_Notice;
			}
        }

		[Serializable]
		public class TBL_Notice
		{
			public int ID { get; set; }
			public string Subject { get; set; }
			public string Body0 { get; set; }
			public DateTime PublishDate { get; set; }
			public DateTime ExpiredDate { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDatetime { get; set; }

			public TBL_Notice()
			{
				this.ID = 0;
				this.Subject = "";
				this.Body0 = "";
				this.PublishDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ExpiredDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_Notice(int ID, string Subject, string Body0, DateTime PublishDate, DateTime ExpiredDate, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDatetime)
			{
				this.ID = ID;
				this.Subject = Subject;
				this.Body0 = Body0;
				this.PublishDate = PublishDate;
				this.ExpiredDate = ExpiredDate;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDatetime = ModifiedDatetime;
			}

			public void CopyTo(ref TBL_Notice to)
			{
				to.ID = this.ID;
				to.Subject = this.Subject;
				to.Body0 = this.Body0;
				to.PublishDate = this.PublishDate;
				to.ExpiredDate = this.ExpiredDate;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDatetime = this.ModifiedDatetime;
			}

			public bool IsSame(TBL_Notice x)
			{
				return(
					this.ID == x.ID &&
					this.Subject == x.Subject &&
					this.Body0 == x.Body0 &&
					this.PublishDate == x.PublishDate &&
					this.ExpiredDate == x.ExpiredDate &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDatetime == x.ModifiedDatetime
				);
			}

			public static TBL_Notice ReadRow(DataRow row)
			{
				TBL_Notice record = new TBL_Notice();
				record.ID = get_int_value(row["ID"]);
				record.Subject = get_string_value(row["Subject"]);
				record.Body0 = get_string_value(row["Body0"]);
				record.PublishDate = get_DateTime_value(row["PublishDate"]);
				record.ExpiredDate = get_DateTime_value(row["ExpiredDate"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDatetime = get_DateTime_value(row["ModifiedDatetime"]);
				return record;
			}

			public static List<TBL_Notice> ReadTable(DataTable dt)
			{
				List<TBL_Notice> records = new List<TBL_Notice>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_Notice
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_Notice(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, Subject, Body0, PublishDate, ExpiredDate, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from Notice
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "Notice.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "Notice.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_Notice data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_Notice.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Notice.ID, Notice.Subject, Notice.Body0, Notice.PublishDate, Notice.ExpiredDate, Notice.CreatedBy, Notice.CreatedDatetime, Notice.ModifiedBy, Notice.ModifiedDatetime
					from Notice
					where Notice.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "Notice.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, Subject, Body0, PublishDate, ExpiredDate, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime
					from Notice
					", ref dt);
                if (!_ok) m_db.LastError = "Notice.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "Notice.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Notice.ID, Notice.Subject, Notice.Body0, Notice.PublishDate, Notice.ExpiredDate, Notice.CreatedBy, Notice.CreatedDatetime, Notice.ModifiedBy, Notice.ModifiedDatetime
					from Notice
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "Notice.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Notice.ID, Notice.Subject, Notice.Body0, Notice.PublishDate, Notice.ExpiredDate, Notice.CreatedBy, Notice.CreatedDatetime, Notice.ModifiedBy, Notice.ModifiedDatetime
					from Notice
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "Notice.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string Subject,
				string Body0,
				DateTime PublishDate,
				DateTime ExpiredDate,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into Notice(
						Subject,
						Body0,
						PublishDate,
						ExpiredDate,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDatetime
						)
					values(
						@Subject,
						@Body0,
						@PublishDate,
						@ExpiredDate,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDatetime
						)
					", Subject, Body0, PublishDate, ExpiredDate, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDatetime);
                if (!_ok) m_db.LastError = "Notice.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string Subject,
				string Body0,
				DateTime PublishDate,
				DateTime ExpiredDate,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Notice where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Notice.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Notice.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update Notice
					set
						Subject = @Subject,
						Body0 = @Body0,
						PublishDate = @PublishDate,
						ExpiredDate = @ExpiredDate,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDatetime = @ModifiedDatetime
					where ID=@ID
					",
					Subject,
					Body0,
					PublishDate,
					ExpiredDate,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDatetime,
					ID
				);
                if (!_ok) m_db.LastError = "Notice.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Notice where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Notice.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Notice.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from Notice where ID=@ID", ID);
                if (!_ok) m_db.LastError = "Notice.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region Organization
		//**********************************************************
		//  Organization
		//**********************************************************
        CMD_Organization m_Organization = null;
        public CMD_Organization Organization
        {
            get
            {
				if (m_Organization == null)
					m_Organization = new CMD_Organization(this);
				return m_Organization;
			}
        }

		[Serializable]
		public class TBL_Organization
		{
			public int ID { get; set; }
			public string OrgIDName { get; set; }
			public string OrgName { get; set; }
			public int IsMinistry { get; set; }
			public int OrgStatus { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }

			public TBL_Organization()
			{
				this.ID = 0;
				this.OrgIDName = "";
				this.OrgName = "";
				this.IsMinistry = 0;
				this.OrgStatus = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_Organization(int ID, string OrgIDName, string OrgName, int IsMinistry, int OrgStatus, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime)
			{
				this.ID = ID;
				this.OrgIDName = OrgIDName;
				this.OrgName = OrgName;
				this.IsMinistry = IsMinistry;
				this.OrgStatus = OrgStatus;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
			}

			public void CopyTo(ref TBL_Organization to)
			{
				to.ID = this.ID;
				to.OrgIDName = this.OrgIDName;
				to.OrgName = this.OrgName;
				to.IsMinistry = this.IsMinistry;
				to.OrgStatus = this.OrgStatus;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
			}

			public bool IsSame(TBL_Organization x)
			{
				return(
					this.ID == x.ID &&
					this.OrgIDName == x.OrgIDName &&
					this.OrgName == x.OrgName &&
					this.IsMinistry == x.IsMinistry &&
					this.OrgStatus == x.OrgStatus &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime
				);
			}

			public static TBL_Organization ReadRow(DataRow row)
			{
				TBL_Organization record = new TBL_Organization();
				record.ID = get_int_value(row["ID"]);
				record.OrgIDName = get_string_value(row["OrgIDName"]);
				record.OrgName = get_string_value(row["OrgName"]);
				record.IsMinistry = get_int_value(row["IsMinistry"]);
				record.OrgStatus = get_int_value(row["OrgStatus"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				return record;
			}

			public static List<TBL_Organization> ReadTable(DataTable dt)
			{
				List<TBL_Organization> records = new List<TBL_Organization>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_Organization
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_Organization(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, OrgIDName, OrgName, IsMinistry, OrgStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from Organization
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "Organization.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "Organization.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_Organization data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_Organization.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Organization.ID, Organization.OrgIDName, Organization.OrgName, Organization.IsMinistry, Organization.OrgStatus, Organization.CreatedBy, Organization.CreatedDatetime, Organization.ModifiedBy, Organization.ModifiedDateTime
					from Organization
					where Organization.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "Organization.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, OrgIDName, OrgName, IsMinistry, OrgStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from Organization
					", ref dt);
                if (!_ok) m_db.LastError = "Organization.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "Organization.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Organization.ID, Organization.OrgIDName, Organization.OrgName, Organization.IsMinistry, Organization.OrgStatus, Organization.CreatedBy, Organization.CreatedDatetime, Organization.ModifiedBy, Organization.ModifiedDateTime
					from Organization
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "Organization.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Organization.ID, Organization.OrgIDName, Organization.OrgName, Organization.IsMinistry, Organization.OrgStatus, Organization.CreatedBy, Organization.CreatedDatetime, Organization.ModifiedBy, Organization.ModifiedDateTime
					from Organization
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "Organization.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string OrgIDName,
				string OrgName,
				int IsMinistry,
				int OrgStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into Organization(
						OrgIDName,
						OrgName,
						IsMinistry,
						OrgStatus,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime
						)
					values(
						@OrgIDName,
						@OrgName,
						@IsMinistry,
						@OrgStatus,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime
						)
					", OrgIDName, OrgName, IsMinistry, OrgStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime);
                if (!_ok) m_db.LastError = "Organization.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string OrgIDName,
				string OrgName,
				int IsMinistry,
				int OrgStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Organization where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Organization.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Organization.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update Organization
					set
						OrgIDName = @OrgIDName,
						OrgName = @OrgName,
						IsMinistry = @IsMinistry,
						OrgStatus = @OrgStatus,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime
					where ID=@ID
					",
					OrgIDName,
					OrgName,
					IsMinistry,
					OrgStatus,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					ID
				);
                if (!_ok) m_db.LastError = "Organization.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Organization where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Organization.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Organization.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from Organization where ID=@ID", ID);
                if (!_ok) m_db.LastError = "Organization.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ReasonsInChangeRequest
		//**********************************************************
		//  ReasonsInChangeRequest
		//**********************************************************
        CMD_ReasonsInChangeRequest m_ReasonsInChangeRequest = null;
        public CMD_ReasonsInChangeRequest ReasonsInChangeRequest
        {
            get
            {
				if (m_ReasonsInChangeRequest == null)
					m_ReasonsInChangeRequest = new CMD_ReasonsInChangeRequest(this);
				return m_ReasonsInChangeRequest;
			}
        }

		[Serializable]
		public class TBL_ReasonsInChangeRequest
		{
			public int ID { get; set; }
			public int ChangeRequestID { get; set; }
			public int ChangeRequestReasonID { get; set; }

			public TBL_ReasonsInChangeRequest()
			{
				this.ID = 0;
				this.ChangeRequestID = 0;
				this.ChangeRequestReasonID = 0;
			}

			public TBL_ReasonsInChangeRequest(int ID, int ChangeRequestID, int ChangeRequestReasonID)
			{
				this.ID = ID;
				this.ChangeRequestID = ChangeRequestID;
				this.ChangeRequestReasonID = ChangeRequestReasonID;
			}

			public void CopyTo(ref TBL_ReasonsInChangeRequest to)
			{
				to.ID = this.ID;
				to.ChangeRequestID = this.ChangeRequestID;
				to.ChangeRequestReasonID = this.ChangeRequestReasonID;
			}

			public bool IsSame(TBL_ReasonsInChangeRequest x)
			{
				return(
					this.ID == x.ID &&
					this.ChangeRequestID == x.ChangeRequestID &&
					this.ChangeRequestReasonID == x.ChangeRequestReasonID
				);
			}

			public static TBL_ReasonsInChangeRequest ReadRow(DataRow row)
			{
				TBL_ReasonsInChangeRequest record = new TBL_ReasonsInChangeRequest();
				record.ID = get_int_value(row["ID"]);
				record.ChangeRequestID = get_int_value(row["ChangeRequestID"]);
				record.ChangeRequestReasonID = get_int_value(row["ChangeRequestReasonID"]);
				return record;
			}

			public static List<TBL_ReasonsInChangeRequest> ReadTable(DataTable dt)
			{
				List<TBL_ReasonsInChangeRequest> records = new List<TBL_ReasonsInChangeRequest>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ReasonsInChangeRequest
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ReasonsInChangeRequest(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ChangeRequestID, ChangeRequestReasonID
					from ReasonsInChangeRequest
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ReasonsInChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ReasonsInChangeRequest.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ReasonsInChangeRequest data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ReasonsInChangeRequest.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ReasonsInChangeRequest.ID, ReasonsInChangeRequest.ChangeRequestID, ReasonsInChangeRequest.ChangeRequestReasonID
					from ReasonsInChangeRequest
					where ReasonsInChangeRequest.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ChangeRequestID, ChangeRequestReasonID
					from ReasonsInChangeRequest
					", ref dt);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ReasonsInChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ReasonsInChangeRequest.ID, ReasonsInChangeRequest.ChangeRequestID, ReasonsInChangeRequest.ChangeRequestReasonID
					from ReasonsInChangeRequest
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ReasonsInChangeRequest.ID, ReasonsInChangeRequest.ChangeRequestID, ReasonsInChangeRequest.ChangeRequestReasonID
					from ReasonsInChangeRequest
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ChangeRequestID,
				int ChangeRequestReasonID
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into ReasonsInChangeRequest(
						ChangeRequestID,
						ChangeRequestReasonID
						)
					values(
						@ChangeRequestID,
						@ChangeRequestReasonID
						)
					", ChangeRequestID, ChangeRequestReasonID);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int ChangeRequestID,
				int ChangeRequestReasonID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ReasonsInChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ReasonsInChangeRequest.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ReasonsInChangeRequest.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ReasonsInChangeRequest
					set
						ChangeRequestID = @ChangeRequestID,
						ChangeRequestReasonID = @ChangeRequestReasonID
					where ID=@ID
					",
					ChangeRequestID,
					ChangeRequestReasonID,
					ID
				);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ReasonsInChangeRequest where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ReasonsInChangeRequest.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ReasonsInChangeRequest.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ReasonsInChangeRequest where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ReasonsInChangeRequest.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ResourceMenu
		//**********************************************************
		//  ResourceMenu
		//**********************************************************
        CMD_ResourceMenu m_ResourceMenu = null;
        public CMD_ResourceMenu ResourceMenu
        {
            get
            {
				if (m_ResourceMenu == null)
					m_ResourceMenu = new CMD_ResourceMenu(this);
				return m_ResourceMenu;
			}
        }

		[Serializable]
		public class TBL_ResourceMenu
		{
			public int ID { get; set; }
			public int Parent { get; set; }
			public string ResourceName { get; set; }
			public string PageURL { get; set; }
			public int Status { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }
			public int PageOrder { get; set; }

			public TBL_ResourceMenu()
			{
				this.ID = 0;
				this.Parent = 0;
				this.ResourceName = "";
				this.PageURL = "";
				this.Status = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.PageOrder = 0;
			}

			public TBL_ResourceMenu(int ID, int Parent, string ResourceName, string PageURL, int Status, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime, int PageOrder)
			{
				this.ID = ID;
				this.Parent = Parent;
				this.ResourceName = ResourceName;
				this.PageURL = PageURL;
				this.Status = Status;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
				this.PageOrder = PageOrder;
			}

			public void CopyTo(ref TBL_ResourceMenu to)
			{
				to.ID = this.ID;
				to.Parent = this.Parent;
				to.ResourceName = this.ResourceName;
				to.PageURL = this.PageURL;
				to.Status = this.Status;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
				to.PageOrder = this.PageOrder;
			}

			public bool IsSame(TBL_ResourceMenu x)
			{
				return(
					this.ID == x.ID &&
					this.Parent == x.Parent &&
					this.ResourceName == x.ResourceName &&
					this.PageURL == x.PageURL &&
					this.Status == x.Status &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime &&
					this.PageOrder == x.PageOrder
				);
			}

			public static TBL_ResourceMenu ReadRow(DataRow row)
			{
				TBL_ResourceMenu record = new TBL_ResourceMenu();
				record.ID = get_int_value(row["ID"]);
				record.Parent = get_int_value(row["Parent"]);
				record.ResourceName = get_string_value(row["ResourceName"]);
				record.PageURL = get_string_value(row["PageURL"]);
				record.Status = get_int_value(row["Status"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				record.PageOrder = get_int_value(row["PageOrder"]);
				return record;
			}

			public static List<TBL_ResourceMenu> ReadTable(DataTable dt)
			{
				List<TBL_ResourceMenu> records = new List<TBL_ResourceMenu>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ResourceMenu
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ResourceMenu(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, Parent, ResourceName, PageURL, Status, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, PageOrder
					from ResourceMenu
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ResourceMenu.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ResourceMenu.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ResourceMenu data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ResourceMenu.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ResourceMenu.ID, ResourceMenu.Parent, ResourceMenu.ResourceName, ResourceMenu.PageURL, ResourceMenu.Status, ResourceMenu.CreatedBy, ResourceMenu.CreatedDatetime, ResourceMenu.ModifiedBy, ResourceMenu.ModifiedDateTime, ResourceMenu.PageOrder
					from ResourceMenu
					where ResourceMenu.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ResourceMenu.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, Parent, ResourceName, PageURL, Status, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, PageOrder
					from ResourceMenu
					", ref dt);
                if (!_ok) m_db.LastError = "ResourceMenu.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ResourceMenu.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ResourceMenu.ID, ResourceMenu.Parent, ResourceMenu.ResourceName, ResourceMenu.PageURL, ResourceMenu.Status, ResourceMenu.CreatedBy, ResourceMenu.CreatedDatetime, ResourceMenu.ModifiedBy, ResourceMenu.ModifiedDateTime, ResourceMenu.PageOrder
					from ResourceMenu
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ResourceMenu.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ResourceMenu.ID, ResourceMenu.Parent, ResourceMenu.ResourceName, ResourceMenu.PageURL, ResourceMenu.Status, ResourceMenu.CreatedBy, ResourceMenu.CreatedDatetime, ResourceMenu.ModifiedBy, ResourceMenu.ModifiedDateTime, ResourceMenu.PageOrder
					from ResourceMenu
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ResourceMenu.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int Parent,
				string ResourceName,
				string PageURL,
				int Status,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				int PageOrder
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into ResourceMenu(
						Parent,
						ResourceName,
						PageURL,
						Status,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime,
						PageOrder
						)
					values(
						@Parent,
						@ResourceName,
						@PageURL,
						@Status,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime,
						@PageOrder
						)
					", Parent, ResourceName, PageURL, Status, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, PageOrder);
                if (!_ok) m_db.LastError = "ResourceMenu.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int Parent,
				string ResourceName,
				string PageURL,
				int Status,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				int PageOrder
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ResourceMenu where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ResourceMenu.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ResourceMenu.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ResourceMenu
					set
						Parent = @Parent,
						ResourceName = @ResourceName,
						PageURL = @PageURL,
						Status = @Status,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime,
						PageOrder = @PageOrder
					where ID=@ID
					",
					Parent,
					ResourceName,
					PageURL,
					Status,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					PageOrder,
					ID
				);
                if (!_ok) m_db.LastError = "ResourceMenu.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ResourceMenu where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ResourceMenu.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ResourceMenu.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ResourceMenu where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ResourceMenu.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region ServiceForm
		//**********************************************************
		//  ServiceForm
		//**********************************************************
        CMD_ServiceForm m_ServiceForm = null;
        public CMD_ServiceForm ServiceForm
        {
            get
            {
				if (m_ServiceForm == null)
					m_ServiceForm = new CMD_ServiceForm(this);
				return m_ServiceForm;
			}
        }

		[Serializable]
		public class TBL_ServiceForm
		{
			public int ID { get; set; }
			public string SRUniqueID { get; set; }
			public string DraftName { get; set; }
			public int SRType { get; set; }
			public int ToSiteID { get; set; }
			public int ToCostCentreID { get; set; }
			public int CostCentreId { get; set; }
			public int SRStatus { get; set; }
			public string Remarks { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int SubmitedBy { get; set; }
			public DateTime SubmitedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDatetime { get; set; }
			public int CloseBy { get; set; }
			public DateTime CloseDatetime { get; set; }
			public int CancelBy { get; set; }
			public DateTime CancelDatetime { get; set; }
			public int RejectBy { get; set; }
			public DateTime RejectDatetime { get; set; }
			public int ParentUniqueSRID { get; set; }
			public int IsUrgent { get; set; }
			public DateTime AckDatetime { get; set; }
			public int AckBy { get; set; }
			public DateTime EffectiveDate { get; set; }

			public TBL_ServiceForm()
			{
				this.ID = 0;
				this.SRUniqueID = "";
				this.DraftName = "";
				this.SRType = 0;
				this.ToSiteID = 0;
				this.ToCostCentreID = 0;
				this.CostCentreId = 0;
				this.SRStatus = 0;
				this.Remarks = "";
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.SubmitedBy = 0;
				this.SubmitedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.CloseBy = 0;
				this.CloseDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.CancelBy = 0;
				this.CancelDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.RejectBy = 0;
				this.RejectDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ParentUniqueSRID = 0;
				this.IsUrgent = 0;
				this.AckDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.AckBy = 0;
				this.EffectiveDate = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_ServiceForm(int ID, string SRUniqueID, string DraftName, int SRType, int ToSiteID, int ToCostCentreID, int CostCentreId, int SRStatus, string Remarks, int CreatedBy, DateTime CreatedDatetime, int SubmitedBy, DateTime SubmitedDatetime, int ModifiedBy, DateTime ModifiedDatetime, int CloseBy, DateTime CloseDatetime, int CancelBy, DateTime CancelDatetime, int RejectBy, DateTime RejectDatetime, int ParentUniqueSRID, int IsUrgent, DateTime AckDatetime, int AckBy, DateTime EffectiveDate)
			{
				this.ID = ID;
				this.SRUniqueID = SRUniqueID;
				this.DraftName = DraftName;
				this.SRType = SRType;
				this.ToSiteID = ToSiteID;
				this.ToCostCentreID = ToCostCentreID;
				this.CostCentreId = CostCentreId;
				this.SRStatus = SRStatus;
				this.Remarks = Remarks;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.SubmitedBy = SubmitedBy;
				this.SubmitedDatetime = SubmitedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDatetime = ModifiedDatetime;
				this.CloseBy = CloseBy;
				this.CloseDatetime = CloseDatetime;
				this.CancelBy = CancelBy;
				this.CancelDatetime = CancelDatetime;
				this.RejectBy = RejectBy;
				this.RejectDatetime = RejectDatetime;
				this.ParentUniqueSRID = ParentUniqueSRID;
				this.IsUrgent = IsUrgent;
				this.AckDatetime = AckDatetime;
				this.AckBy = AckBy;
				this.EffectiveDate = EffectiveDate;
			}

			public void CopyTo(ref TBL_ServiceForm to)
			{
				to.ID = this.ID;
				to.SRUniqueID = this.SRUniqueID;
				to.DraftName = this.DraftName;
				to.SRType = this.SRType;
				to.ToSiteID = this.ToSiteID;
				to.ToCostCentreID = this.ToCostCentreID;
				to.CostCentreId = this.CostCentreId;
				to.SRStatus = this.SRStatus;
				to.Remarks = this.Remarks;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.SubmitedBy = this.SubmitedBy;
				to.SubmitedDatetime = this.SubmitedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDatetime = this.ModifiedDatetime;
				to.CloseBy = this.CloseBy;
				to.CloseDatetime = this.CloseDatetime;
				to.CancelBy = this.CancelBy;
				to.CancelDatetime = this.CancelDatetime;
				to.RejectBy = this.RejectBy;
				to.RejectDatetime = this.RejectDatetime;
				to.ParentUniqueSRID = this.ParentUniqueSRID;
				to.IsUrgent = this.IsUrgent;
				to.AckDatetime = this.AckDatetime;
				to.AckBy = this.AckBy;
				to.EffectiveDate = this.EffectiveDate;
			}

			public bool IsSame(TBL_ServiceForm x)
			{
				return(
					this.ID == x.ID &&
					this.SRUniqueID == x.SRUniqueID &&
					this.DraftName == x.DraftName &&
					this.SRType == x.SRType &&
					this.ToSiteID == x.ToSiteID &&
					this.ToCostCentreID == x.ToCostCentreID &&
					this.CostCentreId == x.CostCentreId &&
					this.SRStatus == x.SRStatus &&
					this.Remarks == x.Remarks &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.SubmitedBy == x.SubmitedBy &&
					this.SubmitedDatetime == x.SubmitedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDatetime == x.ModifiedDatetime &&
					this.CloseBy == x.CloseBy &&
					this.CloseDatetime == x.CloseDatetime &&
					this.CancelBy == x.CancelBy &&
					this.CancelDatetime == x.CancelDatetime &&
					this.RejectBy == x.RejectBy &&
					this.RejectDatetime == x.RejectDatetime &&
					this.ParentUniqueSRID == x.ParentUniqueSRID &&
					this.IsUrgent == x.IsUrgent &&
					this.AckDatetime == x.AckDatetime &&
					this.AckBy == x.AckBy &&
					this.EffectiveDate == x.EffectiveDate
				);
			}

			public static TBL_ServiceForm ReadRow(DataRow row)
			{
				TBL_ServiceForm record = new TBL_ServiceForm();
				record.ID = get_int_value(row["ID"]);
				record.SRUniqueID = get_string_value(row["SRUniqueID"]);
				record.DraftName = get_string_value(row["DraftName"]);
				record.SRType = get_int_value(row["SRType"]);
				record.ToSiteID = get_int_value(row["ToSiteID"]);
				record.ToCostCentreID = get_int_value(row["ToCostCentreID"]);
				record.CostCentreId = get_int_value(row["CostCentreId"]);
				record.SRStatus = get_int_value(row["SRStatus"]);
				record.Remarks = get_string_value(row["Remarks"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.SubmitedBy = get_int_value(row["SubmitedBy"]);
				record.SubmitedDatetime = get_DateTime_value(row["SubmitedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDatetime = get_DateTime_value(row["ModifiedDatetime"]);
				record.CloseBy = get_int_value(row["CloseBy"]);
				record.CloseDatetime = get_DateTime_value(row["CloseDatetime"]);
				record.CancelBy = get_int_value(row["CancelBy"]);
				record.CancelDatetime = get_DateTime_value(row["CancelDatetime"]);
				record.RejectBy = get_int_value(row["RejectBy"]);
				record.RejectDatetime = get_DateTime_value(row["RejectDatetime"]);
				record.ParentUniqueSRID = get_int_value(row["ParentUniqueSRID"]);
				record.IsUrgent = get_int_value(row["IsUrgent"]);
				record.AckDatetime = get_DateTime_value(row["AckDatetime"]);
				record.AckBy = get_int_value(row["AckBy"]);
				record.EffectiveDate = get_DateTime_value(row["EffectiveDate"]);
				return record;
			}

			public static List<TBL_ServiceForm> ReadTable(DataTable dt)
			{
				List<TBL_ServiceForm> records = new List<TBL_ServiceForm>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_ServiceForm
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_ServiceForm(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, SRUniqueID, DraftName, SRType, ToSiteID, ToCostCentreID, CostCentreId, SRStatus, Remarks, CreatedBy, CreatedDatetime, SubmitedBy, SubmitedDatetime, ModifiedBy, ModifiedDatetime, CloseBy, CloseDatetime, CancelBy, CancelDatetime, RejectBy, RejectDatetime, ParentUniqueSRID, IsUrgent, AckDatetime, AckBy, EffectiveDate
					from ServiceForm
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "ServiceForm.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "ServiceForm.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_ServiceForm data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_ServiceForm.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ServiceForm.ID, ServiceForm.SRUniqueID, ServiceForm.DraftName, ServiceForm.SRType, ServiceForm.ToSiteID, ServiceForm.ToCostCentreID, ServiceForm.CostCentreId, ServiceForm.SRStatus, ServiceForm.Remarks, ServiceForm.CreatedBy, ServiceForm.CreatedDatetime, ServiceForm.SubmitedBy, ServiceForm.SubmitedDatetime, ServiceForm.ModifiedBy, ServiceForm.ModifiedDatetime, ServiceForm.CloseBy, ServiceForm.CloseDatetime, ServiceForm.CancelBy, ServiceForm.CancelDatetime, ServiceForm.RejectBy, ServiceForm.RejectDatetime, ServiceForm.ParentUniqueSRID, ServiceForm.IsUrgent, ServiceForm.AckDatetime, ServiceForm.AckBy, ServiceForm.EffectiveDate
					from ServiceForm
					where ServiceForm.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "ServiceForm.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, SRUniqueID, DraftName, SRType, ToSiteID, ToCostCentreID, CostCentreId, SRStatus, Remarks, CreatedBy, CreatedDatetime, SubmitedBy, SubmitedDatetime, ModifiedBy, ModifiedDatetime, CloseBy, CloseDatetime, CancelBy, CancelDatetime, RejectBy, RejectDatetime, ParentUniqueSRID, IsUrgent, AckDatetime, AckBy, EffectiveDate
					from ServiceForm
					", ref dt);
                if (!_ok) m_db.LastError = "ServiceForm.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "ServiceForm.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ServiceForm.ID, ServiceForm.SRUniqueID, ServiceForm.DraftName, ServiceForm.SRType, ServiceForm.ToSiteID, ServiceForm.ToCostCentreID, ServiceForm.CostCentreId, ServiceForm.SRStatus, ServiceForm.Remarks, ServiceForm.CreatedBy, ServiceForm.CreatedDatetime, ServiceForm.SubmitedBy, ServiceForm.SubmitedDatetime, ServiceForm.ModifiedBy, ServiceForm.ModifiedDatetime, ServiceForm.CloseBy, ServiceForm.CloseDatetime, ServiceForm.CancelBy, ServiceForm.CancelDatetime, ServiceForm.RejectBy, ServiceForm.RejectDatetime, ServiceForm.ParentUniqueSRID, ServiceForm.IsUrgent, ServiceForm.AckDatetime, ServiceForm.AckBy, ServiceForm.EffectiveDate
					from ServiceForm
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "ServiceForm.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ServiceForm.ID, ServiceForm.SRUniqueID, ServiceForm.DraftName, ServiceForm.SRType, ServiceForm.ToSiteID, ServiceForm.ToCostCentreID, ServiceForm.CostCentreId, ServiceForm.SRStatus, ServiceForm.Remarks, ServiceForm.CreatedBy, ServiceForm.CreatedDatetime, ServiceForm.SubmitedBy, ServiceForm.SubmitedDatetime, ServiceForm.ModifiedBy, ServiceForm.ModifiedDatetime, ServiceForm.CloseBy, ServiceForm.CloseDatetime, ServiceForm.CancelBy, ServiceForm.CancelDatetime, ServiceForm.RejectBy, ServiceForm.RejectDatetime, ServiceForm.ParentUniqueSRID, ServiceForm.IsUrgent, ServiceForm.AckDatetime, ServiceForm.AckBy, ServiceForm.EffectiveDate
					from ServiceForm
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "ServiceForm.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string SRUniqueID,
				string DraftName,
				int SRType,
				int ToSiteID,
				int ToCostCentreID,
				int CostCentreId,
				int SRStatus,
				string Remarks,
				int CreatedBy,
				DateTime CreatedDatetime,
				int SubmitedBy,
				DateTime SubmitedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime,
				int CloseBy,
				DateTime CloseDatetime,
				int CancelBy,
				DateTime CancelDatetime,
				int RejectBy,
				DateTime RejectDatetime,
				int ParentUniqueSRID,
				int IsUrgent,
				DateTime AckDatetime,
				int AckBy,
				DateTime EffectiveDate
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into ServiceForm(
						SRUniqueID,
						DraftName,
						SRType,
						ToSiteID,
						ToCostCentreID,
						CostCentreId,
						SRStatus,
						Remarks,
						CreatedBy,
						CreatedDatetime,
						SubmitedBy,
						SubmitedDatetime,
						ModifiedBy,
						ModifiedDatetime,
						CloseBy,
						CloseDatetime,
						CancelBy,
						CancelDatetime,
						RejectBy,
						RejectDatetime,
						ParentUniqueSRID,
						IsUrgent,
						AckDatetime,
						AckBy,
						EffectiveDate
						)
					values(
						@SRUniqueID,
						@DraftName,
						@SRType,
						@ToSiteID,
						@ToCostCentreID,
						@CostCentreId,
						@SRStatus,
						@Remarks,
						@CreatedBy,
						@CreatedDatetime,
						@SubmitedBy,
						@SubmitedDatetime,
						@ModifiedBy,
						@ModifiedDatetime,
						@CloseBy,
						@CloseDatetime,
						@CancelBy,
						@CancelDatetime,
						@RejectBy,
						@RejectDatetime,
						@ParentUniqueSRID,
						@IsUrgent,
						@AckDatetime,
						@AckBy,
						@EffectiveDate
						)
					", SRUniqueID, DraftName, SRType, ToSiteID, ToCostCentreID, CostCentreId, SRStatus, Remarks, CreatedBy, CreatedDatetime, SubmitedBy, SubmitedDatetime, ModifiedBy, ModifiedDatetime, CloseBy, CloseDatetime, CancelBy, CancelDatetime, RejectBy, RejectDatetime, ParentUniqueSRID, IsUrgent, AckDatetime, AckBy, EffectiveDate);
                if (!_ok) m_db.LastError = "ServiceForm.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				string SRUniqueID,
				string DraftName,
				int SRType,
				int ToSiteID,
				int ToCostCentreID,
				int CostCentreId,
				int SRStatus,
				string Remarks,
				int CreatedBy,
				DateTime CreatedDatetime,
				int SubmitedBy,
				DateTime SubmitedDatetime,
				int ModifiedBy,
				DateTime ModifiedDatetime,
				int CloseBy,
				DateTime CloseDatetime,
				int CancelBy,
				DateTime CancelDatetime,
				int RejectBy,
				DateTime RejectDatetime,
				int ParentUniqueSRID,
				int IsUrgent,
				DateTime AckDatetime,
				int AckBy,
				DateTime EffectiveDate
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ServiceForm where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ServiceForm.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ServiceForm.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update ServiceForm
					set
						SRUniqueID = @SRUniqueID,
						DraftName = @DraftName,
						SRType = @SRType,
						ToSiteID = @ToSiteID,
						ToCostCentreID = @ToCostCentreID,
						CostCentreId = @CostCentreId,
						SRStatus = @SRStatus,
						Remarks = @Remarks,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						SubmitedBy = @SubmitedBy,
						SubmitedDatetime = @SubmitedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDatetime = @ModifiedDatetime,
						CloseBy = @CloseBy,
						CloseDatetime = @CloseDatetime,
						CancelBy = @CancelBy,
						CancelDatetime = @CancelDatetime,
						RejectBy = @RejectBy,
						RejectDatetime = @RejectDatetime,
						ParentUniqueSRID = @ParentUniqueSRID,
						IsUrgent = @IsUrgent,
						AckDatetime = @AckDatetime,
						AckBy = @AckBy,
						EffectiveDate = @EffectiveDate
					where ID=@ID
					",
					SRUniqueID,
					DraftName,
					SRType,
					ToSiteID,
					ToCostCentreID,
					CostCentreId,
					SRStatus,
					Remarks,
					CreatedBy,
					CreatedDatetime,
					SubmitedBy,
					SubmitedDatetime,
					ModifiedBy,
					ModifiedDatetime,
					CloseBy,
					CloseDatetime,
					CancelBy,
					CancelDatetime,
					RejectBy,
					RejectDatetime,
					ParentUniqueSRID,
					IsUrgent,
					AckDatetime,
					AckBy,
					EffectiveDate,
					ID
				);
                if (!_ok) m_db.LastError = "ServiceForm.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from ServiceForm where ID=@ID", ref count, ID))
				{
					m_db.LastError = "ServiceForm.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "ServiceForm.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from ServiceForm where ID=@ID", ID);
                if (!_ok) m_db.LastError = "ServiceForm.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region SitesInOrganization
		//**********************************************************
		//  SitesInOrganization
		//**********************************************************
        CMD_SitesInOrganization m_SitesInOrganization = null;
        public CMD_SitesInOrganization SitesInOrganization
        {
            get
            {
				if (m_SitesInOrganization == null)
					m_SitesInOrganization = new CMD_SitesInOrganization(this);
				return m_SitesInOrganization;
			}
        }

		[Serializable]
		public class TBL_SitesInOrganization
		{
			public int ID { get; set; }
			public int OrgID { get; set; }
			public string SiteIDName { get; set; }
			public string SiteName { get; set; }
			public int SiteStatus { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }

			public TBL_SitesInOrganization()
			{
				this.ID = 0;
				this.OrgID = 0;
				this.SiteIDName = "";
				this.SiteName = "";
				this.SiteStatus = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_SitesInOrganization(int ID, int OrgID, string SiteIDName, string SiteName, int SiteStatus, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime)
			{
				this.ID = ID;
				this.OrgID = OrgID;
				this.SiteIDName = SiteIDName;
				this.SiteName = SiteName;
				this.SiteStatus = SiteStatus;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
			}

			public void CopyTo(ref TBL_SitesInOrganization to)
			{
				to.ID = this.ID;
				to.OrgID = this.OrgID;
				to.SiteIDName = this.SiteIDName;
				to.SiteName = this.SiteName;
				to.SiteStatus = this.SiteStatus;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
			}

			public bool IsSame(TBL_SitesInOrganization x)
			{
				return(
					this.ID == x.ID &&
					this.OrgID == x.OrgID &&
					this.SiteIDName == x.SiteIDName &&
					this.SiteName == x.SiteName &&
					this.SiteStatus == x.SiteStatus &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime
				);
			}

			public static TBL_SitesInOrganization ReadRow(DataRow row)
			{
				TBL_SitesInOrganization record = new TBL_SitesInOrganization();
				record.ID = get_int_value(row["ID"]);
				record.OrgID = get_int_value(row["OrgID"]);
				record.SiteIDName = get_string_value(row["SiteIDName"]);
				record.SiteName = get_string_value(row["SiteName"]);
				record.SiteStatus = get_int_value(row["SiteStatus"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				return record;
			}

			public static List<TBL_SitesInOrganization> ReadTable(DataTable dt)
			{
				List<TBL_SitesInOrganization> records = new List<TBL_SitesInOrganization>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_SitesInOrganization
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_SitesInOrganization(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, OrgID, SiteIDName, SiteName, SiteStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from SitesInOrganization
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "SitesInOrganization.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "SitesInOrganization.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_SitesInOrganization data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_SitesInOrganization.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select SitesInOrganization.ID, SitesInOrganization.OrgID, SitesInOrganization.SiteIDName, SitesInOrganization.SiteName, SitesInOrganization.SiteStatus, SitesInOrganization.CreatedBy, SitesInOrganization.CreatedDatetime, SitesInOrganization.ModifiedBy, SitesInOrganization.ModifiedDateTime
					from SitesInOrganization
					where SitesInOrganization.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "SitesInOrganization.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, OrgID, SiteIDName, SiteName, SiteStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime
					from SitesInOrganization
					", ref dt);
                if (!_ok) m_db.LastError = "SitesInOrganization.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "SitesInOrganization.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select SitesInOrganization.ID, SitesInOrganization.OrgID, SitesInOrganization.SiteIDName, SitesInOrganization.SiteName, SitesInOrganization.SiteStatus, SitesInOrganization.CreatedBy, SitesInOrganization.CreatedDatetime, SitesInOrganization.ModifiedBy, SitesInOrganization.ModifiedDateTime
					from SitesInOrganization
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "SitesInOrganization.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select SitesInOrganization.ID, SitesInOrganization.OrgID, SitesInOrganization.SiteIDName, SitesInOrganization.SiteName, SitesInOrganization.SiteStatus, SitesInOrganization.CreatedBy, SitesInOrganization.CreatedDatetime, SitesInOrganization.ModifiedBy, SitesInOrganization.ModifiedDateTime
					from SitesInOrganization
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "SitesInOrganization.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int OrgID,
				string SiteIDName,
				string SiteName,
				int SiteStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into SitesInOrganization(
						OrgID,
						SiteIDName,
						SiteName,
						SiteStatus,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime
						)
					values(
						@OrgID,
						@SiteIDName,
						@SiteName,
						@SiteStatus,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime
						)
					", OrgID, SiteIDName, SiteName, SiteStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime);
                if (!_ok) m_db.LastError = "SitesInOrganization.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int OrgID,
				string SiteIDName,
				string SiteName,
				int SiteStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from SitesInOrganization where ID=@ID", ref count, ID))
				{
					m_db.LastError = "SitesInOrganization.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "SitesInOrganization.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update SitesInOrganization
					set
						OrgID = @OrgID,
						SiteIDName = @SiteIDName,
						SiteName = @SiteName,
						SiteStatus = @SiteStatus,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime
					where ID=@ID
					",
					OrgID,
					SiteIDName,
					SiteName,
					SiteStatus,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					ID
				);
                if (!_ok) m_db.LastError = "SitesInOrganization.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from SitesInOrganization where ID=@ID", ref count, ID))
				{
					m_db.LastError = "SitesInOrganization.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "SitesInOrganization.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from SitesInOrganization where ID=@ID", ID);
                if (!_ok) m_db.LastError = "SitesInOrganization.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region Subscriber
		//**********************************************************
		//  Subscriber
		//**********************************************************
        CMD_Subscriber m_Subscriber = null;
        public CMD_Subscriber Subscriber
        {
            get
            {
				if (m_Subscriber == null)
					m_Subscriber = new CMD_Subscriber(this);
				return m_Subscriber;
			}
        }

		[Serializable]
		public class TBL_Subscriber
		{
			public int ID { get; set; }
			public int ServiceFormID { get; set; }
			public int MasterProfileID { get; set; }
			public DateTime EffectiveDate { get; set; }
			public DateTime TerminatedDate { get; set; }
			public int TerminatedBy { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }
			public int CostCentreID { get; set; }
			public string Email { get; set; }
			public string Username { get; set; }
			public string ServiceType { get; set; }
			public string AssetID { get; set; }
			public string Hostname { get; set; }
			public string OS { get; set; }
			public int Status { get; set; }

			public TBL_Subscriber()
			{
				this.ID = 0;
				this.ServiceFormID = 0;
				this.MasterProfileID = 0;
				this.EffectiveDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.TerminatedDate = Convert.ToDateTime("1900-01-01 00:00:00");
				this.TerminatedBy = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.CostCentreID = 0;
				this.Email = "";
				this.Username = "";
				this.ServiceType = "";
				this.AssetID = "";
				this.Hostname = "";
				this.OS = "";
				this.Status = 0;
			}

			public TBL_Subscriber(int ID, int ServiceFormID, int MasterProfileID, DateTime EffectiveDate, DateTime TerminatedDate, int TerminatedBy, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime, int CostCentreID, string Email, string Username, string ServiceType, string AssetID, string Hostname, string OS, int Status)
			{
				this.ID = ID;
				this.ServiceFormID = ServiceFormID;
				this.MasterProfileID = MasterProfileID;
				this.EffectiveDate = EffectiveDate;
				this.TerminatedDate = TerminatedDate;
				this.TerminatedBy = TerminatedBy;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
				this.CostCentreID = CostCentreID;
				this.Email = Email;
				this.Username = Username;
				this.ServiceType = ServiceType;
				this.AssetID = AssetID;
				this.Hostname = Hostname;
				this.OS = OS;
				this.Status = Status;
			}

			public void CopyTo(ref TBL_Subscriber to)
			{
				to.ID = this.ID;
				to.ServiceFormID = this.ServiceFormID;
				to.MasterProfileID = this.MasterProfileID;
				to.EffectiveDate = this.EffectiveDate;
				to.TerminatedDate = this.TerminatedDate;
				to.TerminatedBy = this.TerminatedBy;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
				to.CostCentreID = this.CostCentreID;
				to.Email = this.Email;
				to.Username = this.Username;
				to.ServiceType = this.ServiceType;
				to.AssetID = this.AssetID;
				to.Hostname = this.Hostname;
				to.OS = this.OS;
				to.Status = this.Status;
			}

			public bool IsSame(TBL_Subscriber x)
			{
				return(
					this.ID == x.ID &&
					this.ServiceFormID == x.ServiceFormID &&
					this.MasterProfileID == x.MasterProfileID &&
					this.EffectiveDate == x.EffectiveDate &&
					this.TerminatedDate == x.TerminatedDate &&
					this.TerminatedBy == x.TerminatedBy &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime &&
					this.CostCentreID == x.CostCentreID &&
					this.Email == x.Email &&
					this.Username == x.Username &&
					this.ServiceType == x.ServiceType &&
					this.AssetID == x.AssetID &&
					this.Hostname == x.Hostname &&
					this.OS == x.OS &&
					this.Status == x.Status
				);
			}

			public static TBL_Subscriber ReadRow(DataRow row)
			{
				TBL_Subscriber record = new TBL_Subscriber();
				record.ID = get_int_value(row["ID"]);
				record.ServiceFormID = get_int_value(row["ServiceFormID"]);
				record.MasterProfileID = get_int_value(row["MasterProfileID"]);
				record.EffectiveDate = get_DateTime_value(row["EffectiveDate"]);
				record.TerminatedDate = get_DateTime_value(row["TerminatedDate"]);
				record.TerminatedBy = get_int_value(row["TerminatedBy"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				record.CostCentreID = get_int_value(row["CostCentreID"]);
				record.Email = get_string_value(row["Email"]);
				record.Username = get_string_value(row["Username"]);
				record.ServiceType = get_string_value(row["ServiceType"]);
				record.AssetID = get_string_value(row["AssetID"]);
				record.Hostname = get_string_value(row["Hostname"]);
				record.OS = get_string_value(row["OS"]);
				record.Status = get_int_value(row["Status"]);
				return record;
			}

			public static List<TBL_Subscriber> ReadTable(DataTable dt)
			{
				List<TBL_Subscriber> records = new List<TBL_Subscriber>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_Subscriber
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_Subscriber(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select ID, ServiceFormID, MasterProfileID, EffectiveDate, TerminatedDate, TerminatedBy, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, CostCentreID, Email, Username, ServiceType, AssetID, Hostname, OS, Status
					from Subscriber
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "Subscriber.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where ID=@ID"
					, ID))
                {
                    m_db.LastError = "Subscriber.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int ID,
				ref TBL_Subscriber data
			)
			{
                DataTable dt = null;
				if (!select(
				        ID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_Subscriber.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int ID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Subscriber.ID, Subscriber.ServiceFormID, Subscriber.MasterProfileID, Subscriber.EffectiveDate, Subscriber.TerminatedDate, Subscriber.TerminatedBy, Subscriber.CreatedBy, Subscriber.CreatedDatetime, Subscriber.ModifiedBy, Subscriber.ModifiedDateTime, Subscriber.CostCentreID, Subscriber.Email, Subscriber.Username, Subscriber.ServiceType, Subscriber.AssetID, Subscriber.Hostname, Subscriber.OS, Subscriber.Status
					from Subscriber
					where Subscriber.ID=@ID
					", ref dt, ID);
                if (!_ok) m_db.LastError = "Subscriber.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select ID, ServiceFormID, MasterProfileID, EffectiveDate, TerminatedDate, TerminatedBy, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, CostCentreID, Email, Username, ServiceType, AssetID, Hostname, OS, Status
					from Subscriber
					", ref dt);
                if (!_ok) m_db.LastError = "Subscriber.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "Subscriber.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Subscriber.ID, Subscriber.ServiceFormID, Subscriber.MasterProfileID, Subscriber.EffectiveDate, Subscriber.TerminatedDate, Subscriber.TerminatedBy, Subscriber.CreatedBy, Subscriber.CreatedDatetime, Subscriber.ModifiedBy, Subscriber.ModifiedDateTime, Subscriber.CostCentreID, Subscriber.Email, Subscriber.Username, Subscriber.ServiceType, Subscriber.AssetID, Subscriber.Hostname, Subscriber.OS, Subscriber.Status
					from Subscriber
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "Subscriber.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Subscriber.ID, Subscriber.ServiceFormID, Subscriber.MasterProfileID, Subscriber.EffectiveDate, Subscriber.TerminatedDate, Subscriber.TerminatedBy, Subscriber.CreatedBy, Subscriber.CreatedDatetime, Subscriber.ModifiedBy, Subscriber.ModifiedDateTime, Subscriber.CostCentreID, Subscriber.Email, Subscriber.Username, Subscriber.ServiceType, Subscriber.AssetID, Subscriber.Hostname, Subscriber.OS, Subscriber.Status
					from Subscriber
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "Subscriber.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				int ServiceFormID,
				int MasterProfileID,
				DateTime EffectiveDate,
				DateTime TerminatedDate,
				int TerminatedBy,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				int CostCentreID,
				string Email,
				string Username,
				string ServiceType,
				string AssetID,
				string Hostname,
				string OS,
				int Status
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into Subscriber(
						ServiceFormID,
						MasterProfileID,
						EffectiveDate,
						TerminatedDate,
						TerminatedBy,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime,
						CostCentreID,
						Email,
						Username,
						ServiceType,
						AssetID,
						Hostname,
						OS,
						Status
						)
					values(
						@ServiceFormID,
						@MasterProfileID,
						@EffectiveDate,
						@TerminatedDate,
						@TerminatedBy,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime,
						@CostCentreID,
						@Email,
						@Username,
						@ServiceType,
						@AssetID,
						@Hostname,
						@OS,
						@Status
						)
					", ServiceFormID, MasterProfileID, EffectiveDate, TerminatedDate, TerminatedBy, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, CostCentreID, Email, Username, ServiceType, AssetID, Hostname, OS, Status);
                if (!_ok) m_db.LastError = "Subscriber.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int ID,
				int ServiceFormID,
				int MasterProfileID,
				DateTime EffectiveDate,
				DateTime TerminatedDate,
				int TerminatedBy,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				int CostCentreID,
				string Email,
				string Username,
				string ServiceType,
				string AssetID,
				string Hostname,
				string OS,
				int Status
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Subscriber where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Subscriber.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Subscriber.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update Subscriber
					set
						ServiceFormID = @ServiceFormID,
						MasterProfileID = @MasterProfileID,
						EffectiveDate = @EffectiveDate,
						TerminatedDate = @TerminatedDate,
						TerminatedBy = @TerminatedBy,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime,
						CostCentreID = @CostCentreID,
						Email = @Email,
						Username = @Username,
						ServiceType = @ServiceType,
						AssetID = @AssetID,
						Hostname = @Hostname,
						OS = @OS,
						Status = @Status
					where ID=@ID
					",
					ServiceFormID,
					MasterProfileID,
					EffectiveDate,
					TerminatedDate,
					TerminatedBy,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					CostCentreID,
					Email,
					Username,
					ServiceType,
					AssetID,
					Hostname,
					OS,
					Status,
					ID
				);
                if (!_ok) m_db.LastError = "Subscriber.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int ID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Subscriber where ID=@ID", ref count, ID))
				{
					m_db.LastError = "Subscriber.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Subscriber.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from Subscriber where ID=@ID", ID);
                if (!_ok) m_db.LastError = "Subscriber.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region Subscriber_temp
		//**********************************************************
		//  Subscriber_temp
		//**********************************************************
        CMD_Subscriber_temp m_Subscriber_temp = null;
        public CMD_Subscriber_temp Subscriber_temp
        {
            get
            {
				if (m_Subscriber_temp == null)
					m_Subscriber_temp = new CMD_Subscriber_temp(this);
				return m_Subscriber_temp;
			}
        }

		[Serializable]
		public class TBL_Subscriber_temp
		{
			public string AssetID { get; set; }
			public string Site { get; set; }
			public string Organization { get; set; }
			public string CurrentUser { get; set; }
			public string OS { get; set; }

			public TBL_Subscriber_temp()
			{
				this.AssetID = "";
				this.Site = "";
				this.Organization = "";
				this.CurrentUser = "";
				this.OS = "";
			}

			public TBL_Subscriber_temp(string AssetID, string Site, string Organization, string CurrentUser, string OS)
			{
				this.AssetID = AssetID;
				this.Site = Site;
				this.Organization = Organization;
				this.CurrentUser = CurrentUser;
				this.OS = OS;
			}

			public void CopyTo(ref TBL_Subscriber_temp to)
			{
				to.AssetID = this.AssetID;
				to.Site = this.Site;
				to.Organization = this.Organization;
				to.CurrentUser = this.CurrentUser;
				to.OS = this.OS;
			}

			public bool IsSame(TBL_Subscriber_temp x)
			{
				return(
					this.AssetID == x.AssetID &&
					this.Site == x.Site &&
					this.Organization == x.Organization &&
					this.CurrentUser == x.CurrentUser &&
					this.OS == x.OS
				);
			}

			public static TBL_Subscriber_temp ReadRow(DataRow row)
			{
				TBL_Subscriber_temp record = new TBL_Subscriber_temp();
				record.AssetID = get_string_value(row["AssetID"]);
				record.Site = get_string_value(row["Site"]);
				record.Organization = get_string_value(row["Organization"]);
				record.CurrentUser = get_string_value(row["CurrentUser"]);
				record.OS = get_string_value(row["OS"]);
				return record;
			}

			public static List<TBL_Subscriber_temp> ReadTable(DataTable dt)
			{
				List<TBL_Subscriber_temp> records = new List<TBL_Subscriber_temp>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_Subscriber_temp
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_Subscriber_temp(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select AssetID, Site, Organization, CurrentUser, OS
					from Subscriber_temp
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "Subscriber_temp.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				string AssetID,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where AssetID=@AssetID"
					, AssetID))
                {
                    m_db.LastError = "Subscriber_temp.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				string AssetID,
				ref TBL_Subscriber_temp data
			)
			{
                DataTable dt = null;
				if (!select(
				        AssetID,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_Subscriber_temp.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				string AssetID,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Subscriber_temp.AssetID, Subscriber_temp.Site, Subscriber_temp.Organization, Subscriber_temp.CurrentUser, Subscriber_temp.OS
					from Subscriber_temp
					where Subscriber_temp.AssetID=@AssetID
					", ref dt, AssetID);
                if (!_ok) m_db.LastError = "Subscriber_temp.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select AssetID, Site, Organization, CurrentUser, OS
					from Subscriber_temp
					", ref dt);
                if (!_ok) m_db.LastError = "Subscriber_temp.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "Subscriber_temp.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Subscriber_temp.AssetID, Subscriber_temp.Site, Subscriber_temp.Organization, Subscriber_temp.CurrentUser, Subscriber_temp.OS
					from Subscriber_temp
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "Subscriber_temp.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select Subscriber_temp.AssetID, Subscriber_temp.Site, Subscriber_temp.Organization, Subscriber_temp.CurrentUser, Subscriber_temp.OS
					from Subscriber_temp
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "Subscriber_temp.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string AssetID,
				string Site,
				string Organization,
				string CurrentUser,
				string OS
			)
			{            
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Subscriber_temp where AssetID=@AssetID", ref count, AssetID))
				{
					m_db.LastError = "Subscriber_temp.insert error.\r\n" + m_db.LastError;
					return false;
				}
				if (count > 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Subscriber_temp.insert error. ID duplicate";
					return false;
				}

				bool _ok = m_db.ExecSqlCmd(@"
					insert into Subscriber_temp(
						AssetID,
						Site,
						Organization,
						CurrentUser,
						OS
						)
					values(
						@AssetID,
						@Site,
						@Organization,
						@CurrentUser,
						@OS
						)
					", AssetID, Site, Organization, CurrentUser, OS);
                if (!_ok) m_db.LastError = "Subscriber_temp.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				string _old_AssetID,
				string _new_AssetID,
				string Site,
				string Organization,
				string CurrentUser,
				string OS
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Subscriber_temp where AssetID=@_old_AssetID", ref count, _old_AssetID))
				{
					m_db.LastError = "Subscriber_temp.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Subscriber_temp.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update Subscriber_temp
					set
						AssetID = @_new_AssetID,
						Site = @Site,
						Organization = @Organization,
						CurrentUser = @CurrentUser,
						OS = @OS
					where AssetID=@_old_AssetID
					",
					_new_AssetID,
					Site,
					Organization,
					CurrentUser,
					OS,
					_old_AssetID
				);
                if (!_ok) m_db.LastError = "Subscriber_temp.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				string AssetID
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from Subscriber_temp where AssetID=@AssetID", ref count, AssetID))
				{
					m_db.LastError = "Subscriber_temp.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "Subscriber_temp.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from Subscriber_temp where AssetID=@AssetID", AssetID);
                if (!_ok) m_db.LastError = "Subscriber_temp.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region sysdiagrams
		//**********************************************************
		//  sysdiagrams
		//**********************************************************
        CMD_sysdiagrams m_sysdiagrams = null;
        public CMD_sysdiagrams sysdiagrams
        {
            get
            {
				if (m_sysdiagrams == null)
					m_sysdiagrams = new CMD_sysdiagrams(this);
				return m_sysdiagrams;
			}
        }

		[Serializable]
		public class TBL_sysdiagrams
		{
			public string name { get; set; }
			public int principal_id { get; set; }
			public int diagram_id { get; set; }
			public int version { get; set; }
			public byte[] definition { get; set; }

			public TBL_sysdiagrams()
			{
				this.name = "";
				this.principal_id = 0;
				this.diagram_id = 0;
				this.version = 0;
				this.definition = new byte[0];
			}

			public TBL_sysdiagrams(string name, int principal_id, int diagram_id, int version, byte[] definition)
			{
				this.name = name;
				this.principal_id = principal_id;
				this.diagram_id = diagram_id;
				this.version = version;
				this.definition = definition;
			}

			public void CopyTo(ref TBL_sysdiagrams to)
			{
				to.name = this.name;
				to.principal_id = this.principal_id;
				to.diagram_id = this.diagram_id;
				to.version = this.version;
				to.definition = this.definition;
			}

			public bool IsSame(TBL_sysdiagrams x)
			{
				return(
					this.name == x.name &&
					this.principal_id == x.principal_id &&
					this.diagram_id == x.diagram_id &&
					this.version == x.version &&
					this.definition == x.definition
				);
			}

			public static TBL_sysdiagrams ReadRow(DataRow row)
			{
				TBL_sysdiagrams record = new TBL_sysdiagrams();
				record.name = get_string_value(row["name"]);
				record.principal_id = get_int_value(row["principal_id"]);
				record.diagram_id = get_int_value(row["diagram_id"]);
				record.version = get_int_value(row["version"]);
				record.definition = get_bytes_value(row["definition"]);
				return record;
			}

			public static List<TBL_sysdiagrams> ReadTable(DataTable dt)
			{
				List<TBL_sysdiagrams> records = new List<TBL_sysdiagrams>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_sysdiagrams
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_sysdiagrams(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select name, principal_id, diagram_id, version, definition
					from sysdiagrams
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "sysdiagrams.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int diagram_id,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where diagram_id=@diagram_id"
					, diagram_id))
                {
                    m_db.LastError = "sysdiagrams.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int diagram_id,
				ref TBL_sysdiagrams data
			)
			{
                DataTable dt = null;
				if (!select(
				        diagram_id,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_sysdiagrams.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int diagram_id,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select sysdiagrams.name, sysdiagrams.principal_id, sysdiagrams.diagram_id, sysdiagrams.version, sysdiagrams.definition
					from sysdiagrams
					where sysdiagrams.diagram_id=@diagram_id
					", ref dt, diagram_id);
                if (!_ok) m_db.LastError = "sysdiagrams.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select name, principal_id, diagram_id, version, definition
					from sysdiagrams
					", ref dt);
                if (!_ok) m_db.LastError = "sysdiagrams.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "sysdiagrams.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select sysdiagrams.name, sysdiagrams.principal_id, sysdiagrams.diagram_id, sysdiagrams.version, sysdiagrams.definition
					from sysdiagrams
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "sysdiagrams.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select sysdiagrams.name, sysdiagrams.principal_id, sysdiagrams.diagram_id, sysdiagrams.version, sysdiagrams.definition
					from sysdiagrams
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "sysdiagrams.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string name,
				int principal_id,
				int version,
				byte[] definition
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into sysdiagrams(
						name,
						principal_id,
						version,
						definition
						)
					values(
						@name,
						@principal_id,
						@version,
						@definition
						)
					", name, principal_id, version, definition);
                if (!_ok) m_db.LastError = "sysdiagrams.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int diagram_id,
				string name,
				int principal_id,
				int version,
				byte[] definition
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from sysdiagrams where diagram_id=@diagram_id", ref count, diagram_id))
				{
					m_db.LastError = "sysdiagrams.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "sysdiagrams.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update sysdiagrams
					set
						name = @name,
						principal_id = @principal_id,
						version = @version,
						definition = @definition
					where diagram_id=@diagram_id
					",
					name,
					principal_id,
					version,
					definition,
					diagram_id
				);
                if (!_ok) m_db.LastError = "sysdiagrams.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int diagram_id
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from sysdiagrams where diagram_id=@diagram_id", ref count, diagram_id))
				{
					m_db.LastError = "sysdiagrams.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "sysdiagrams.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from sysdiagrams where diagram_id=@diagram_id", diagram_id);
                if (!_ok) m_db.LastError = "sysdiagrams.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion

		#region UserProfile
		//**********************************************************
		//  UserProfile
		//**********************************************************
        CMD_UserProfile m_UserProfile = null;
        public CMD_UserProfile UserProfile
        {
            get
            {
				if (m_UserProfile == null)
					m_UserProfile = new CMD_UserProfile(this);
				return m_UserProfile;
			}
        }

		[Serializable]
		public class TBL_UserProfile
		{
			public int UserId { get; set; }
			public string LoginId { get; set; }
			public string LoginPassword { get; set; }
			public string NRIC { get; set; }
			public string Name0 { get; set; }
			public string Address01 { get; set; }
			public string Address02 { get; set; }
			public string PostCode { get; set; }
			public string PrimaryPhone { get; set; }
			public string SecondaryPhone { get; set; }
			public string FaxNumber { get; set; }
			public string Email { get; set; }
			public int UserTypeId { get; set; }
			public int OrgID { get; set; }
			public int SiteID { get; set; }
			public int CostCentreID { get; set; }
			public int UserStatus { get; set; }
			public int CreatedBy { get; set; }
			public DateTime CreatedDatetime { get; set; }
			public int ModifiedBy { get; set; }
			public DateTime ModifiedDateTime { get; set; }
			public DateTime LastLogin { get; set; }

			public TBL_UserProfile()
			{
				this.UserId = 0;
				this.LoginId = "";
				this.LoginPassword = "";
				this.NRIC = "";
				this.Name0 = "";
				this.Address01 = "";
				this.Address02 = "";
				this.PostCode = "";
				this.PrimaryPhone = "";
				this.SecondaryPhone = "";
				this.FaxNumber = "";
				this.Email = "";
				this.UserTypeId = 0;
				this.OrgID = 0;
				this.SiteID = 0;
				this.CostCentreID = 0;
				this.UserStatus = 0;
				this.CreatedBy = 0;
				this.CreatedDatetime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.ModifiedBy = 0;
				this.ModifiedDateTime = Convert.ToDateTime("1900-01-01 00:00:00");
				this.LastLogin = Convert.ToDateTime("1900-01-01 00:00:00");
			}

			public TBL_UserProfile(int UserId, string LoginId, string LoginPassword, string NRIC, string Name0, string Address01, string Address02, string PostCode, string PrimaryPhone, string SecondaryPhone, string FaxNumber, string Email, int UserTypeId, int OrgID, int SiteID, int CostCentreID, int UserStatus, int CreatedBy, DateTime CreatedDatetime, int ModifiedBy, DateTime ModifiedDateTime, DateTime LastLogin)
			{
				this.UserId = UserId;
				this.LoginId = LoginId;
				this.LoginPassword = LoginPassword;
				this.NRIC = NRIC;
				this.Name0 = Name0;
				this.Address01 = Address01;
				this.Address02 = Address02;
				this.PostCode = PostCode;
				this.PrimaryPhone = PrimaryPhone;
				this.SecondaryPhone = SecondaryPhone;
				this.FaxNumber = FaxNumber;
				this.Email = Email;
				this.UserTypeId = UserTypeId;
				this.OrgID = OrgID;
				this.SiteID = SiteID;
				this.CostCentreID = CostCentreID;
				this.UserStatus = UserStatus;
				this.CreatedBy = CreatedBy;
				this.CreatedDatetime = CreatedDatetime;
				this.ModifiedBy = ModifiedBy;
				this.ModifiedDateTime = ModifiedDateTime;
				this.LastLogin = LastLogin;
			}

			public void CopyTo(ref TBL_UserProfile to)
			{
				to.UserId = this.UserId;
				to.LoginId = this.LoginId;
				to.LoginPassword = this.LoginPassword;
				to.NRIC = this.NRIC;
				to.Name0 = this.Name0;
				to.Address01 = this.Address01;
				to.Address02 = this.Address02;
				to.PostCode = this.PostCode;
				to.PrimaryPhone = this.PrimaryPhone;
				to.SecondaryPhone = this.SecondaryPhone;
				to.FaxNumber = this.FaxNumber;
				to.Email = this.Email;
				to.UserTypeId = this.UserTypeId;
				to.OrgID = this.OrgID;
				to.SiteID = this.SiteID;
				to.CostCentreID = this.CostCentreID;
				to.UserStatus = this.UserStatus;
				to.CreatedBy = this.CreatedBy;
				to.CreatedDatetime = this.CreatedDatetime;
				to.ModifiedBy = this.ModifiedBy;
				to.ModifiedDateTime = this.ModifiedDateTime;
				to.LastLogin = this.LastLogin;
			}

			public bool IsSame(TBL_UserProfile x)
			{
				return(
					this.UserId == x.UserId &&
					this.LoginId == x.LoginId &&
					this.LoginPassword == x.LoginPassword &&
					this.NRIC == x.NRIC &&
					this.Name0 == x.Name0 &&
					this.Address01 == x.Address01 &&
					this.Address02 == x.Address02 &&
					this.PostCode == x.PostCode &&
					this.PrimaryPhone == x.PrimaryPhone &&
					this.SecondaryPhone == x.SecondaryPhone &&
					this.FaxNumber == x.FaxNumber &&
					this.Email == x.Email &&
					this.UserTypeId == x.UserTypeId &&
					this.OrgID == x.OrgID &&
					this.SiteID == x.SiteID &&
					this.CostCentreID == x.CostCentreID &&
					this.UserStatus == x.UserStatus &&
					this.CreatedBy == x.CreatedBy &&
					this.CreatedDatetime == x.CreatedDatetime &&
					this.ModifiedBy == x.ModifiedBy &&
					this.ModifiedDateTime == x.ModifiedDateTime &&
					this.LastLogin == x.LastLogin
				);
			}

			public static TBL_UserProfile ReadRow(DataRow row)
			{
				TBL_UserProfile record = new TBL_UserProfile();
				record.UserId = get_int_value(row["UserId"]);
				record.LoginId = get_string_value(row["LoginId"]);
				record.LoginPassword = get_string_value(row["LoginPassword"]);
				record.NRIC = get_string_value(row["NRIC"]);
				record.Name0 = get_string_value(row["Name0"]);
				record.Address01 = get_string_value(row["Address01"]);
				record.Address02 = get_string_value(row["Address02"]);
				record.PostCode = get_string_value(row["PostCode"]);
				record.PrimaryPhone = get_string_value(row["PrimaryPhone"]);
				record.SecondaryPhone = get_string_value(row["SecondaryPhone"]);
				record.FaxNumber = get_string_value(row["FaxNumber"]);
				record.Email = get_string_value(row["Email"]);
				record.UserTypeId = get_int_value(row["UserTypeId"]);
				record.OrgID = get_int_value(row["OrgID"]);
				record.SiteID = get_int_value(row["SiteID"]);
				record.CostCentreID = get_int_value(row["CostCentreID"]);
				record.UserStatus = get_int_value(row["UserStatus"]);
				record.CreatedBy = get_int_value(row["CreatedBy"]);
				record.CreatedDatetime = get_DateTime_value(row["CreatedDatetime"]);
				record.ModifiedBy = get_int_value(row["ModifiedBy"]);
				record.ModifiedDateTime = get_DateTime_value(row["ModifiedDateTime"]);
				record.LastLogin = get_DateTime_value(row["LastLogin"]);
				return record;
			}

			public static List<TBL_UserProfile> ReadTable(DataTable dt)
			{
				List<TBL_UserProfile> records = new List<TBL_UserProfile>();
				foreach(DataRow row in dt.Rows)
					records.Add(ReadRow(row));
				return records;
			}
		}

        public class CMD_UserProfile
        {
            private MyLib.DBCommandsBase m_db = null;

			public CMD_UserProfile(MyLib.DBCommandsBase db)
			{
				m_db = db;
			}

			public bool select
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				if (!m_db.ExecSqlQuery(@"
					select UserId, LoginId, LoginPassword, NRIC, Name0, Address01, Address02, PostCode, PrimaryPhone, SecondaryPhone, FaxNumber, Email, UserTypeId, OrgID, SiteID, CostCentreID, UserStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, LastLogin
					from UserProfile
					" + where_clause, ref dt, inputs))
                {
                    m_db.LastError = "UserProfile.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int UserId,
				ref DataTable dt
			)
			{
				if (!select(ref dt, @"where UserId=@UserId"
					, UserId))
                {
                    m_db.LastError = "UserProfile.select error.\r\n" + m_db.LastError;
                    return false;
                }
                return true;
			}

			public bool select
			(
				int UserId,
				ref TBL_UserProfile data
			)
			{
                DataTable dt = null;
				if (!select(
				        UserId,
				        ref dt))
                    return false;
                if (dt.Rows.Count == 0)
                    data = null;
                else
                    data = TBL_UserProfile.ReadRow(dt.Rows[0]);
                return true;
			}

			public bool select_join
			(
				int UserId,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select UserProfile.UserId, UserProfile.LoginId, UserProfile.LoginPassword, UserProfile.NRIC, UserProfile.Name0, UserProfile.Address01, UserProfile.Address02, UserProfile.PostCode, UserProfile.PrimaryPhone, UserProfile.SecondaryPhone, UserProfile.FaxNumber, UserProfile.Email, UserProfile.UserTypeId, UserProfile.OrgID, UserProfile.SiteID, UserProfile.CostCentreID, UserProfile.UserStatus, UserProfile.CreatedBy, UserProfile.CreatedDatetime, UserProfile.ModifiedBy, UserProfile.ModifiedDateTime, UserProfile.LastLogin
					from UserProfile
					where UserProfile.UserId=@UserId
					", ref dt, UserId);
                if (!_ok) m_db.LastError = "UserProfile.select error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all
			(
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select UserId, LoginId, LoginPassword, NRIC, Name0, Address01, Address02, PostCode, PrimaryPhone, SecondaryPhone, FaxNumber, Email, UserTypeId, OrgID, SiteID, CostCentreID, UserStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, LastLogin
					from UserProfile
					", ref dt);
                if (!_ok) m_db.LastError = "UserProfile.select_all error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt
			)
			{
				bool _ok = select_all_join(ref dt, "");
				if (!_ok) m_db.LastError = "UserProfile.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool select_all_join
			(
				ref DataTable dt,
				string where_clause,
                params object[] inputs
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select UserProfile.UserId, UserProfile.LoginId, UserProfile.LoginPassword, UserProfile.NRIC, UserProfile.Name0, UserProfile.Address01, UserProfile.Address02, UserProfile.PostCode, UserProfile.PrimaryPhone, UserProfile.SecondaryPhone, UserProfile.FaxNumber, UserProfile.Email, UserProfile.UserTypeId, UserProfile.OrgID, UserProfile.SiteID, UserProfile.CostCentreID, UserProfile.UserStatus, UserProfile.CreatedBy, UserProfile.CreatedDatetime, UserProfile.ModifiedBy, UserProfile.ModifiedDateTime, UserProfile.LastLogin
					from UserProfile
					" + where_clause, ref dt, inputs);
                if (!_ok) m_db.LastError = "UserProfile.select_all_join error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool query
			(
				string where_clause,
				ref DataTable dt
			)
			{
				bool _ok = m_db.ExecSqlQuery(@"
					select UserProfile.UserId, UserProfile.LoginId, UserProfile.LoginPassword, UserProfile.NRIC, UserProfile.Name0, UserProfile.Address01, UserProfile.Address02, UserProfile.PostCode, UserProfile.PrimaryPhone, UserProfile.SecondaryPhone, UserProfile.FaxNumber, UserProfile.Email, UserProfile.UserTypeId, UserProfile.OrgID, UserProfile.SiteID, UserProfile.CostCentreID, UserProfile.UserStatus, UserProfile.CreatedBy, UserProfile.CreatedDatetime, UserProfile.ModifiedBy, UserProfile.ModifiedDateTime, UserProfile.LastLogin
					from UserProfile
					" + " " + where_clause, ref dt);
                if (!_ok) m_db.LastError = "UserProfile.query error.\r\n" + m_db.LastError;
                return _ok;
			}


            public bool insert
			(
				string LoginId,
				string LoginPassword,
				string NRIC,
				string Name0,
				string Address01,
				string Address02,
				string PostCode,
				string PrimaryPhone,
				string SecondaryPhone,
				string FaxNumber,
				string Email,
				int UserTypeId,
				int OrgID,
				int SiteID,
				int CostCentreID,
				int UserStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				DateTime LastLogin
			)
			{            
				bool _ok = m_db.ExecSqlCmd(@"
					insert into UserProfile(
						LoginId,
						LoginPassword,
						NRIC,
						Name0,
						Address01,
						Address02,
						PostCode,
						PrimaryPhone,
						SecondaryPhone,
						FaxNumber,
						Email,
						UserTypeId,
						OrgID,
						SiteID,
						CostCentreID,
						UserStatus,
						CreatedBy,
						CreatedDatetime,
						ModifiedBy,
						ModifiedDateTime,
						LastLogin
						)
					values(
						@LoginId,
						@LoginPassword,
						@NRIC,
						@Name0,
						@Address01,
						@Address02,
						@PostCode,
						@PrimaryPhone,
						@SecondaryPhone,
						@FaxNumber,
						@Email,
						@UserTypeId,
						@OrgID,
						@SiteID,
						@CostCentreID,
						@UserStatus,
						@CreatedBy,
						@CreatedDatetime,
						@ModifiedBy,
						@ModifiedDateTime,
						@LastLogin
						)
					", LoginId, LoginPassword, NRIC, Name0, Address01, Address02, PostCode, PrimaryPhone, SecondaryPhone, FaxNumber, Email, UserTypeId, OrgID, SiteID, CostCentreID, UserStatus, CreatedBy, CreatedDatetime, ModifiedBy, ModifiedDateTime, LastLogin);
                if (!_ok) m_db.LastError = "UserProfile.insert error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool update
			(
				int UserId,
				string LoginId,
				string LoginPassword,
				string NRIC,
				string Name0,
				string Address01,
				string Address02,
				string PostCode,
				string PrimaryPhone,
				string SecondaryPhone,
				string FaxNumber,
				string Email,
				int UserTypeId,
				int OrgID,
				int SiteID,
				int CostCentreID,
				int UserStatus,
				int CreatedBy,
				DateTime CreatedDatetime,
				int ModifiedBy,
				DateTime ModifiedDateTime,
				DateTime LastLogin
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from UserProfile where UserId=@UserId", ref count, UserId))
				{
					m_db.LastError = "UserProfile.update error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "UserProfile.update error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"
					update UserProfile
					set
						LoginId = @LoginId,
						LoginPassword = @LoginPassword,
						NRIC = @NRIC,
						Name0 = @Name0,
						Address01 = @Address01,
						Address02 = @Address02,
						PostCode = @PostCode,
						PrimaryPhone = @PrimaryPhone,
						SecondaryPhone = @SecondaryPhone,
						FaxNumber = @FaxNumber,
						Email = @Email,
						UserTypeId = @UserTypeId,
						OrgID = @OrgID,
						SiteID = @SiteID,
						CostCentreID = @CostCentreID,
						UserStatus = @UserStatus,
						CreatedBy = @CreatedBy,
						CreatedDatetime = @CreatedDatetime,
						ModifiedBy = @ModifiedBy,
						ModifiedDateTime = @ModifiedDateTime,
						LastLogin = @LastLogin
					where UserId=@UserId
					",
					LoginId,
					LoginPassword,
					NRIC,
					Name0,
					Address01,
					Address02,
					PostCode,
					PrimaryPhone,
					SecondaryPhone,
					FaxNumber,
					Email,
					UserTypeId,
					OrgID,
					SiteID,
					CostCentreID,
					UserStatus,
					CreatedBy,
					CreatedDatetime,
					ModifiedBy,
					ModifiedDateTime,
					LastLogin,
					UserId
				);
                if (!_ok) m_db.LastError = "UserProfile.update error.\r\n" + m_db.LastError;
                return _ok;
			}

			public bool delete
			(				
				int UserId
			)
			{
				int count = 0;
				if (!m_db.ExecSqlQueryCount(@"select * from UserProfile where UserId=@UserId", ref count, UserId))
				{
					m_db.LastError = "UserProfile.delete error.\r\n" + m_db.LastError;
					return false;
				}
				if (count == 0)
				{
					m_db.LastErrorCode = -1;
					m_db.LastError = "UserProfile.delete error. ID does not exists";
					return false;
				}
                
				bool _ok = m_db.ExecSqlCmd(@"delete from UserProfile where UserId=@UserId", UserId);
                if (!_ok) m_db.LastError = "UserProfile.delete error.\r\n" + m_db.LastError;
                return _ok;
			}
        
		}

		#endregion


		public bool sp_0
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_0", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_0 error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_alterdiagram
		(
			string diagramname,
			int owner_id,
			int version,
			byte[] definition
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_alterdiagram", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, diagramname);
				AddParam(sqlCmd, "@owner_id", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, owner_id);
				AddParam(sqlCmd, "@version", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, version);
				AddParam(sqlCmd, "@definition", SqlDbType.VarBinary, -1, -1, 0, ParameterDirection.Input, definition);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_alterdiagram error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInChangeRequest_DeleteByChangeRequestIDRole
		(
			int ChangeRequestID,
			int ChangeRequestRole
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInChangeRequest_DeleteByChangeRequestIDRole", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				AddParam(sqlCmd, "@ChangeRequestRole", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRole);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInChangeRequest_DeleteByChangeRequestIDRole error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInChangeRequest_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInChangeRequest_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInChangeRequest_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInChangeRequest_Insert
		(
			int ChangeRequestID,
			int ChangeRequestRole,
			string AttachmentName,
			byte[] AttachmentDetails,
			string AttachmentContentType,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInChangeRequest_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				AddParam(sqlCmd, "@ChangeRequestRole", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRole);
				AddParam(sqlCmd, "@AttachmentName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, AttachmentName);
				AddParam(sqlCmd, "@AttachmentDetails", SqlDbType.Image, 16, 0, 0, ParameterDirection.Input, AttachmentDetails);
				AddParam(sqlCmd, "@AttachmentContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, AttachmentContentType);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInChangeRequest_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_AttachmentsInChangeRequest_SelectByChangeRequestIDRole
		(
			int ChangeRequestID,
			int ChangeRequestRole
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_AttachmentsInChangeRequest_SelectByChangeRequestIDRole", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				AddParam(sqlCmd, "@ChangeRequestRole", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRole);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_AttachmentsInChangeRequest_SelectByChangeRequestIDRole error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_AttachmentsInChangeRequest_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_AttachmentsInChangeRequest_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_AttachmentsInChangeRequest_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInChangeRequest_UpdateByID
		(
			int ID,
			int ChangeRequestID,
			int ChangeRequestRole,
			string AttachmentName,
			byte[] AttachmentDetails,
			string AttachmentContentType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInChangeRequest_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				AddParam(sqlCmd, "@ChangeRequestRole", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRole);
				AddParam(sqlCmd, "@AttachmentName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, AttachmentName);
				AddParam(sqlCmd, "@AttachmentDetails", SqlDbType.Image, 16, 0, 0, ParameterDirection.Input, AttachmentDetails);
				AddParam(sqlCmd, "@AttachmentContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, AttachmentContentType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInChangeRequest_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInNotice_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInNotice_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInNotice_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInNotice_DeleteByNoticeID
		(
			int NoticeID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInNotice_DeleteByNoticeID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@NoticeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, NoticeID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInNotice_DeleteByNoticeID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInNotice_Insert
		(
			int NoticeID,
			byte[] AttachmentDetails,
			string AttachmentName,
			string AttachmentContentType,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInNotice_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@NoticeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, NoticeID);
				AddParam(sqlCmd, "@AttachmentDetails", SqlDbType.Image, 16, 0, 0, ParameterDirection.Input, AttachmentDetails);
				AddParam(sqlCmd, "@AttachmentName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, AttachmentName);
				AddParam(sqlCmd, "@AttachmentContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, AttachmentContentType);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInNotice_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInNotice_SelectAll
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInNotice_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInNotice_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_AttachmentsInNotice_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_AttachmentsInNotice_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_AttachmentsInNotice_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInNotice_SelectByNoticeID
		(
			int NoticeID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInNotice_SelectByNoticeID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@NoticeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, NoticeID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInNotice_SelectByNoticeID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AttachmentsInNotice_UpdateByID
		(
			int ID,
			int NoticeID,
			byte[] AttachmentDetails,
			string AttachmentName,
			string AttachmentContentType,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AttachmentsInNotice_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@NoticeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, NoticeID);
				AddParam(sqlCmd, "@AttachmentDetails", SqlDbType.Image, 16, 0, 0, ParameterDirection.Input, AttachmentDetails);
				AddParam(sqlCmd, "@AttachmentName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, AttachmentName);
				AddParam(sqlCmd, "@AttachmentContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, AttachmentContentType);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AttachmentsInNotice_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_AuditTrail_Insert
		(
			DateTime datetime,
			string script,
			string user,
			string action,
			string table,
			string field,
			string keyvalue,
			string oldvalue,
			string newvalue
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_AuditTrail_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@datetime", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, datetime);
				AddParam(sqlCmd, "@script", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, script);
				AddParam(sqlCmd, "@user", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, user);
				AddParam(sqlCmd, "@action", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, action);
				AddParam(sqlCmd, "@table", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, table);
				AddParam(sqlCmd, "@field", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, field);
				AddParam(sqlCmd, "@keyvalue", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, keyvalue);
				AddParam(sqlCmd, "@oldvalue", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, oldvalue);
				AddParam(sqlCmd, "@newvalue", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, newvalue);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_AuditTrail_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_BackupDatabase
		(
			string databaseName,
			string backupType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_BackupDatabase", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@databaseName", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, databaseName);
				AddParam(sqlCmd, "@backupType", SqlDbType.VarChar, 1, 1, 0, ParameterDirection.Input, backupType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_BackupDatabase error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Bill_Generate
		(
			int BillPeriodID,
			ref string GenerateOutput
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Bill_Generate", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@GenerateOutput", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				GenerateOutput = get_string_value(sqlCmd.Parameters["@GenerateOutput"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Bill_Generate error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillConfig_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillConfig_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillConfig_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_Insert
		(
			string BillType,
			string CustNo,
			string CustName1,
			string CustName2,
			string BUCode,
			string Address,
			string ContactPerson,
			string PaymentTerm,
			string SpecialInstruction,
			string GroupBy,
			int SiteID,
			string TelNo,
			string FaxNo,
			string EmailTo,
			string Remarks,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				AddParam(sqlCmd, "@CustNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, CustNo);
				AddParam(sqlCmd, "@CustName1", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, CustName1);
				AddParam(sqlCmd, "@CustName2", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, CustName2);
				AddParam(sqlCmd, "@BUCode", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, BUCode);
				AddParam(sqlCmd, "@Address", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, Address);
				AddParam(sqlCmd, "@ContactPerson", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ContactPerson);
				AddParam(sqlCmd, "@PaymentTerm", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, PaymentTerm);
				AddParam(sqlCmd, "@SpecialInstruction", SqlDbType.VarChar, 1000, 500, 0, ParameterDirection.Input, SpecialInstruction);
				AddParam(sqlCmd, "@GroupBy", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, GroupBy);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@TelNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, TelNo);
				AddParam(sqlCmd, "@FaxNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, FaxNo);
				AddParam(sqlCmd, "@EmailTo", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, EmailTo);
				AddParam(sqlCmd, "@Remarks", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Remarks);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectByBillingRecipientEmail
		(
			string Email
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectByBillingRecipientEmail", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectByBillingRecipientEmail error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectByBillType
		(
			string BillType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectByBillType", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectByBillType error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectByBillTypeOrgID
		(
			string BillType,
			int OrgID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectByBillTypeOrgID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectByBillTypeOrgID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectByBillTypeSiteID
		(
			string BillType,
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectByBillTypeSiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectByBillTypeSiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectByBillTypeSiteIDCostCentreID
		(
			string BillType,
			int SiteID,
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectByBillTypeSiteIDCostCentreID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectByBillTypeSiteIDCostCentreID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomer_UpdateByID
		(
			int ID,
			string BillType,
			string CustNo,
			string CustName1,
			string CustName2,
			string BUCode,
			string Address,
			string ContactPerson,
			string PaymentTerm,
			string SpecialInstruction,
			string GroupBy,
			int SiteID,
			string TelNo,
			string FaxNo,
			string EmailTo,
			string Remarks,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomer_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				AddParam(sqlCmd, "@CustNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, CustNo);
				AddParam(sqlCmd, "@CustName1", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, CustName1);
				AddParam(sqlCmd, "@CustName2", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, CustName2);
				AddParam(sqlCmd, "@BUCode", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, BUCode);
				AddParam(sqlCmd, "@Address", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, Address);
				AddParam(sqlCmd, "@ContactPerson", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ContactPerson);
				AddParam(sqlCmd, "@PaymentTerm", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, PaymentTerm);
				AddParam(sqlCmd, "@SpecialInstruction", SqlDbType.VarChar, 1000, 500, 0, ParameterDirection.Input, SpecialInstruction);
				AddParam(sqlCmd, "@GroupBy", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, GroupBy);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@TelNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, TelNo);
				AddParam(sqlCmd, "@FaxNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, FaxNo);
				AddParam(sqlCmd, "@EmailTo", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, EmailTo);
				AddParam(sqlCmd, "@Remarks", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Remarks);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomer_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomerCC_DeleteByBillCustomerID
		(
			int BillCustomerID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomerCC_DeleteByBillCustomerID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomerCC_DeleteByBillCustomerID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomerCC_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomerCC_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomerCC_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomerCC_Insert
		(
			int BillCustomerID,
			int CostCentreID,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomerCC_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomerCC_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomerCC_SelectByBillCustomerID
		(
			int BillCustomerID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomerCC_SelectByBillCustomerID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomerCC_SelectByBillCustomerID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomerCC_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomerCC_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomerCC_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillCustomerCC_UpdateByID
		(
			int ID,
			int BillCustomerID,
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillCustomerCC_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillCustomerCC_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillMonthly_Generate
		(
			int BillPeriodID,
			ref string GenerateOutput
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillMonthly_Generate", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@GenerateOutput", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				GenerateOutput = get_string_value(sqlCmd.Parameters["@GenerateOutput"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillMonthly_Generate error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillMonthly_IsExists
		(
			int BillPeriodID,
			ref int IsExists
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillMonthly_IsExists", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@IsExists", SqlDbType.Int, 1, 1, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				IsExists = get_int_value(sqlCmd.Parameters["@IsExists"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillMonthly_IsExists error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillMonthly_SelectbyBillPeriodBillCustomer
		(
			int BillPeriodID,
			int BillCustomerID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillMonthly_SelectbyBillPeriodBillCustomer", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillMonthly_SelectbyBillPeriodBillCustomer error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillMonthly_SelectByBillPeriodCostCentre
		(
			int BillPeriodID,
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillMonthly_SelectByBillPeriodCostCentre", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillMonthly_SelectByBillPeriodCostCentre error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillMonthly_SelectbyBillPeriodSite
		(
			int BillPeriodID,
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillMonthly_SelectbyBillPeriodSite", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillMonthly_SelectbyBillPeriodSite error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillPeriod_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillPeriod_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillPeriod_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillPeriod_SelectCurrentPreiod
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillPeriod_SelectCurrentPreiod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillPeriod_SelectCurrentPreiod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillPeriod_SelectGeneratedDataPeriod
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillPeriod_SelectGeneratedDataPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillPeriod_SelectGeneratedDataPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillPeriod_SelectGeneratedPeriod
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillPeriod_SelectGeneratedPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillPeriod_SelectGeneratedPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillPeriod_SelectReleasedPeriodByBillingRecipientEmail
		(
			string Email
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillPeriod_SelectReleasedPeriodByBillingRecipientEmail", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillPeriod_SelectReleasedPeriodByBillingRecipientEmail error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillPeriod_SelectReleasedPeriodBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillPeriod_SelectReleasedPeriodBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillPeriod_SelectReleasedPeriodBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillQuarterly_SelectByBillPeriodCostCentre
		(
			int BillPeriodID,
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillQuarterly_SelectByBillPeriodCostCentre", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillQuarterly_SelectByBillPeriodCostCentre error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReport_CCTransferRequest_SelectByBillPeriod
		(
			int BillPeriodID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReport_CCTransferRequest_SelectByBillPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReport_CCTransferRequest_SelectByBillPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReport_ChangeRequest_SelectClosedByBillPeriod
		(
			int BillPeriodID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReport_ChangeRequest_SelectClosedByBillPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReport_ChangeRequest_SelectClosedByBillPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReport_CreationRequest_SelectByBillPeriod
		(
			int BillPeriodID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReport_CreationRequest_SelectByBillPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReport_CreationRequest_SelectByBillPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReport_FinanceSummary_SelectByBillPeriod
		(
			int BillPeriodID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReport_FinanceSummary_SelectByBillPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReport_FinanceSummary_SelectByBillPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReport_ProfileList_SelectByBillPeriod
		(
			int BillPeriodID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReport_ProfileList_SelectByBillPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReport_ProfileList_SelectByBillPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReport_TerminationRequest_SelectByBillPeriod
		(
			int BillPeriodID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReport_TerminationRequest_SelectByBillPeriod", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReport_TerminationRequest_SelectByBillPeriod error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_Insert
		(
			int BillPeriodID,
			int BillReportTemplateID,
			string ReportFileName,
			byte[] ReportData,
			string ContentType,
			int IsReleased,
			int SiteID,
			int CostCentreID,
			int CreatedBy,
			string DownloadID,
			int BillCustomerID,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@BillReportTemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillReportTemplateID);
				AddParam(sqlCmd, "@ReportFileName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ReportFileName);
				AddParam(sqlCmd, "@ReportData", SqlDbType.Image, 16, 0, 0, ParameterDirection.Input, ReportData);
				AddParam(sqlCmd, "@ContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ContentType);
				AddParam(sqlCmd, "@IsReleased", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsReleased);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@DownloadID", SqlDbType.VarChar, 72, 36, 0, ParameterDirection.Input, DownloadID);
				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_ReleaseByID
		(
			int ID,
			int ReleasedBy,
			ref int UpdatedRow
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_ReleaseByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@ReleasedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ReleasedBy);
				AddParam(sqlCmd, "@UpdatedRow", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				UpdatedRow = get_int_value(sqlCmd.Parameters["@UpdatedRow"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_ReleaseByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectAllReleasedWithoutDataByPeriodLoginGroupLoginEmailBillCustomer
		(
			int BillPeriodID,
			int LoginUserGroup,
			string Email,
			int BillCustomerID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectAllReleasedWithoutDataByPeriodLoginGroupLoginEmailBillCustomer", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@LoginUserGroup", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, LoginUserGroup);
				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectAllReleasedWithoutDataByPeriodLoginGroupLoginEmailBillCustomer error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectAllReleasedWithoutDataByPeriodLoginGroupLoginSiteOrgSiteCC
		(
			int BillPeriodID,
			int LoginUserGroup,
			int LoginSiteID,
			int OrgID,
			int SiteID,
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectAllReleasedWithoutDataByPeriodLoginGroupLoginSiteOrgSiteCC", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@LoginUserGroup", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, LoginUserGroup);
				AddParam(sqlCmd, "@LoginSiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, LoginSiteID);
				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectAllReleasedWithoutDataByPeriodLoginGroupLoginSiteOrgSiteCC error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectAllWithoutDataByPeriodOrgSiteCC
		(
			int BillPeriodID,
			int OrgID,
			int SiteID,
			int CostCentreID,
			int FilterByIsReleased,
			int IsReleased
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectAllWithoutDataByPeriodOrgSiteCC", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				AddParam(sqlCmd, "@FilterByIsReleased", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, FilterByIsReleased);
				AddParam(sqlCmd, "@IsReleased", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsReleased);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectAllWithoutDataByPeriodOrgSiteCC error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectBillingRecipientUserIdBySelectedRepositoryID
		(
			string SelectedRepositoryIDList
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectBillingRecipientUserIdBySelectedRepositoryID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SelectedRepositoryIDList", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, SelectedRepositoryIDList);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectBillingRecipientUserIdBySelectedRepositoryID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectByBillPeriodIDBillReportTemplateIDBillCustomerID
		(
			int BillPeriodID,
			int BillReportTemplateID,
			int BillCustomerID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectByBillPeriodIDBillReportTemplateIDBillCustomerID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@BillReportTemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillReportTemplateID);
				AddParam(sqlCmd, "@BillCustomerID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillCustomerID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectByBillPeriodIDBillReportTemplateIDBillCustomerID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectByBillPeriodIDBillReportTemplateIDSiteIDCostCentreID
		(
			int BillPeriodID,
			int BillReportTemplateID,
			int SiteID,
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectByBillPeriodIDBillReportTemplateIDSiteIDCostCentreID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@BillReportTemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillReportTemplateID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectByBillPeriodIDBillReportTemplateIDSiteIDCostCentreID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectByIDDownloadID
		(
			int ID,
			string DownloadID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectByIDDownloadID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@DownloadID", SqlDbType.VarChar, 72, 36, 0, ParameterDirection.Input, DownloadID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectByIDDownloadID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectBySelectedRepositoryIDBillingRecipientUserId
		(
			string SelectedRepositoryIDList,
			int UserId
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectBySelectedRepositoryIDBillingRecipientUserId", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SelectedRepositoryIDList", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, SelectedRepositoryIDList);
				AddParam(sqlCmd, "@UserId", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserId);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectBySelectedRepositoryIDBillingRecipientUserId error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectBySelectedRepositoryIDGroupMemberID
		(
			string SelectedRepositoryIDList,
			int GroupMemberID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectBySelectedRepositoryIDGroupMemberID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SelectedRepositoryIDList", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, SelectedRepositoryIDList);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectBySelectedRepositoryIDGroupMemberID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectBySelectedRepositoryIDGroupMemberIDSiteID
		(
			string SelectedRepositoryIDList,
			int GroupMemberID,
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectBySelectedRepositoryIDGroupMemberIDSiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SelectedRepositoryIDList", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, SelectedRepositoryIDList);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectBySelectedRepositoryIDGroupMemberIDSiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectGroupMemberIDWithNoSiteIDBySelectedRepositoryID
		(
			string SelectedRepositoryIDList
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectGroupMemberIDWithNoSiteIDBySelectedRepositoryID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SelectedRepositoryIDList", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, SelectedRepositoryIDList);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectGroupMemberIDWithNoSiteIDBySelectedRepositoryID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_SelectGroupMemberIDWithSiteIDBySelectedRepositoryID
		(
			string SelectedRepositoryIDList
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_SelectGroupMemberIDWithSiteIDBySelectedRepositoryID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SelectedRepositoryIDList", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, SelectedRepositoryIDList);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_SelectGroupMemberIDWithSiteIDBySelectedRepositoryID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_UnReleaseByID
		(
			int ID,
			int UnReleasedBy,
			ref int UpdatedRow
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_UnReleaseByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@UnReleasedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UnReleasedBy);
				AddParam(sqlCmd, "@UpdatedRow", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				UpdatedRow = get_int_value(sqlCmd.Parameters["@UpdatedRow"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_UnReleaseByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportRepository_UpdateByID
		(
			int ID,
			int BillPeriodID,
			int BillReportTemplateID,
			string ReportFileName,
			byte[] ReportData,
			string ContentType,
			int IsReleased,
			int SiteID,
			int CostCentreID,
			int CreatedBy,
			DateTime CreatedDateTime,
			int ReleasedBy,
			DateTime ReleasedDateTime
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportRepository_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@BillPeriodID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillPeriodID);
				AddParam(sqlCmd, "@BillReportTemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillReportTemplateID);
				AddParam(sqlCmd, "@ReportFileName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ReportFileName);
				AddParam(sqlCmd, "@ReportData", SqlDbType.Image, 16, 0, 0, ParameterDirection.Input, ReportData);
				AddParam(sqlCmd, "@ContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ContentType);
				AddParam(sqlCmd, "@IsReleased", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsReleased);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@CreatedDateTime", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, CreatedDateTime);
				AddParam(sqlCmd, "@ReleasedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ReleasedBy);
				AddParam(sqlCmd, "@ReleasedDateTime", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, ReleasedDateTime);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportRepository_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportTemplate_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportTemplate_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportTemplate_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportTemplate_Insert
		(
			string ReportName,
			string ReportPath,
			string RenderFormat,
			string ReportFileExt,
			string ContentType,
			string DatasetName,
			string StoredProcName,
			string ParameterType,
			int ReportStatus,
			string BillType,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportTemplate_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ReportName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ReportName);
				AddParam(sqlCmd, "@ReportPath", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ReportPath);
				AddParam(sqlCmd, "@RenderFormat", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, RenderFormat);
				AddParam(sqlCmd, "@ReportFileExt", SqlDbType.VarChar, 20, 10, 0, ParameterDirection.Input, ReportFileExt);
				AddParam(sqlCmd, "@ContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ContentType);
				AddParam(sqlCmd, "@DatasetName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, DatasetName);
				AddParam(sqlCmd, "@StoredProcName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, StoredProcName);
				AddParam(sqlCmd, "@ParameterType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ParameterType);
				AddParam(sqlCmd, "@ReportStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, ReportStatus);
				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportTemplate_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportTemplate_SelectAllActive
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportTemplate_SelectAllActive", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportTemplate_SelectAllActive error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportTemplate_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportTemplate_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportTemplate_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportTemplate_UpdateByID
		(
			int ID,
			string ReportName,
			string ReportPath,
			string RenderFormat,
			string ReportFileExt,
			string ContentType,
			string DatasetName,
			string StoredProcName,
			string ParameterType,
			int ReportStatus,
			string BillType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportTemplate_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@ReportName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ReportName);
				AddParam(sqlCmd, "@ReportPath", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ReportPath);
				AddParam(sqlCmd, "@RenderFormat", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, RenderFormat);
				AddParam(sqlCmd, "@ReportFileExt", SqlDbType.VarChar, 20, 10, 0, ParameterDirection.Input, ReportFileExt);
				AddParam(sqlCmd, "@ContentType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ContentType);
				AddParam(sqlCmd, "@DatasetName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, DatasetName);
				AddParam(sqlCmd, "@StoredProcName", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, StoredProcName);
				AddParam(sqlCmd, "@ParameterType", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, ParameterType);
				AddParam(sqlCmd, "@ReportStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, ReportStatus);
				AddParam(sqlCmd, "@BillType", SqlDbType.VarChar, 40, 20, 0, ParameterDirection.Input, BillType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportTemplate_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportUserGroup_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportUserGroup_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportUserGroup_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportUserGroup_Insert
		(
			int BillReportTemplateID,
			int GroupMemberID,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportUserGroup_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@BillReportTemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillReportTemplateID);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportUserGroup_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportUserGroup_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportUserGroup_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportUserGroup_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_BillReportUserGroup_UpdateByID
		(
			int ID,
			int BillReportTemplateID,
			int GroupMemberID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_BillReportUserGroup_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@BillReportTemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, BillReportTemplateID);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_BillReportUserGroup_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_Insert
		(
			string ChangeRequestNo,
			int ChangeRequestTypeID,
			int ChangeRequestStatus,
			string RequestorComment,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, ChangeRequestNo);
				AddParam(sqlCmd, "@ChangeRequestTypeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestTypeID);
				AddParam(sqlCmd, "@ChangeRequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestStatus);
				AddParam(sqlCmd, "@RequestorComment", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, RequestorComment);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_SelectByChangeRequestStatus
		(
			int ChangeRequestStatus
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_SelectByChangeRequestStatus", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestStatus);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_SelectByChangeRequestStatus error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_SelectByIDForReport
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_SelectByIDForReport", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_SelectByIDForReport error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_SelectByIDForTemplate
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_SelectByIDForTemplate", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_SelectByIDForTemplate error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_SelectByLoginID
		(
			string LoginID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_SelectByLoginID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@LoginID", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, LoginID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_SelectByLoginID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_SelectTodayMaxCRNo
		(
			int ChangeRequestStatus
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_SelectTodayMaxCRNo", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestStatus);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_SelectTodayMaxCRNo error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequest_UpdateByID
		(
			int ID,
			string ChangeRequestNo,
			int ChangeRequestTypeID,
			int ChangeRequestStatus,
			string RequestorComment,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequest_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@ChangeRequestNo", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, ChangeRequestNo);
				AddParam(sqlCmd, "@ChangeRequestTypeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestTypeID);
				AddParam(sqlCmd, "@ChangeRequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestStatus);
				AddParam(sqlCmd, "@RequestorComment", SqlDbType.VarChar, -1, -1, 0, ParameterDirection.Input, RequestorComment);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequest_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestForm_Clear
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestForm_Clear", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestForm_Clear error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestReason_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestReason_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestReason_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestRoleGroup_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestRoleGroup_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestRoleGroup_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestRoleGroup_Insert
		(
			int ChangeRequestRoleID,
			int GroupMemberID,
			DateTime CreatedBy,
			DateTime CreatedDatetime,
			int ModifiedBy,
			DateTime ModifiedDatetime,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestRoleGroup_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestRoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRoleID);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@CreatedDatetime", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, CreatedDatetime);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				AddParam(sqlCmd, "@ModifiedDatetime", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, ModifiedDatetime);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestRoleGroup_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestRoleGroup_MatchUserCRRole
		(
			int UseId,
			int ChangeRequestRoleID,
			ref int IsMatch
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestRoleGroup_MatchUserCRRole", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UseId", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UseId);
				AddParam(sqlCmd, "@ChangeRequestRoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRoleID);
				AddParam(sqlCmd, "@IsMatch", SqlDbType.Int, 1, 1, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				IsMatch = get_int_value(sqlCmd.Parameters["@IsMatch"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestRoleGroup_MatchUserCRRole error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestRoleGroup_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestRoleGroup_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestRoleGroup_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestRoleGroup_UpdateByID
		(
			int ID,
			int ChangeRequestRoleID,
			int GroupMemberID,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestRoleGroup_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@ChangeRequestRoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestRoleID);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestRoleGroup_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestStatus_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestStatus_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestStatus_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ChangeRequestType_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ChangeRequestType_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ChangeRequestType_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_Content_Valid
		(
			int UserID,
			string ContentType,
			string ContentID,
			ref int Valid
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_Content_Valid", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@ContentType", SqlDbType.VarChar, 100, 100, 0, ParameterDirection.Input, ContentType);
				AddParam(sqlCmd, "@ContentID", SqlDbType.VarChar, 100, 100, 0, ParameterDirection.Input, ContentID);
				AddParam(sqlCmd, "@Valid", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				Valid = get_int_value(sqlCmd.Parameters["@Valid"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_Content_Valid error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_Insert
		(
			int SiteID,
			string CostCentreIDName,
			string CostCentreName,
			int CostCentreStatus,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreIDName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, CostCentreIDName);
				AddParam(sqlCmd, "@CostCentreName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, CostCentreName);
				AddParam(sqlCmd, "@CostCentreStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, CostCentreStatus);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_SelectActiveBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_SelectActiveBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_SelectActiveBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_SelectBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_SelectBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_SelectBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_SelectOrgSiteCCByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_SelectOrgSiteCCByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_SelectOrgSiteCCByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_SelectOrgSiteCCByOrgID
		(
			int OrgID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_SelectOrgSiteCCByOrgID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_SelectOrgSiteCCByOrgID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_CostCentresInSite_UpdateByID
		(
			int ID,
			int SiteID,
			string CostCentreIDName,
			string CostCentreName,
			int CostCentreStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_CostCentresInSite_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreIDName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, CostCentreIDName);
				AddParam(sqlCmd, "@CostCentreName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, CostCentreName);
				AddParam(sqlCmd, "@CostCentreStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, CostCentreStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_CostCentresInSite_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_creatediagram
		(
			string diagramname,
			int owner_id,
			int version,
			byte[] definition
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_creatediagram", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, diagramname);
				AddParam(sqlCmd, "@owner_id", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, owner_id);
				AddParam(sqlCmd, "@version", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, version);
				AddParam(sqlCmd, "@definition", SqlDbType.VarBinary, -1, -1, 0, ParameterDirection.Input, definition);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_creatediagram error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_DetailsInChangeRequest_DeleteByChangeRequestID
		(
			int ChangeRequestID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_DetailsInChangeRequest_DeleteByChangeRequestID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_DetailsInChangeRequest_DeleteByChangeRequestID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_DetailsInChangeRequest_Insert
		(
			int ChangeRequestID,
			int SubscriberID,
			int New_CostCentreID,
			DateTime New_EffectiveDate,
			DateTime New_TerminatedDate,
			string New_Email,
			string New_Username,
			string New_ServiceType,
			string New_AssetID,
			string New_Hostname,
			string New_OS,
			int New_Status,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_DetailsInChangeRequest_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				AddParam(sqlCmd, "@SubscriberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SubscriberID);
				AddParam(sqlCmd, "@New_CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, New_CostCentreID);
				AddParam(sqlCmd, "@New_EffectiveDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, New_EffectiveDate);
				AddParam(sqlCmd, "@New_TerminatedDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, New_TerminatedDate);
				AddParam(sqlCmd, "@New_Email", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, New_Email);
				AddParam(sqlCmd, "@New_Username", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, New_Username);
				AddParam(sqlCmd, "@New_ServiceType", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, New_ServiceType);
				AddParam(sqlCmd, "@New_AssetID", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, New_AssetID);
				AddParam(sqlCmd, "@New_Hostname", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, New_Hostname);
				AddParam(sqlCmd, "@New_OS", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, New_OS);
				AddParam(sqlCmd, "@New_Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, New_Status);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_DetailsInChangeRequest_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DetailsInChangeRequest_SelectByChangeRequestID
		(
			int ChangeRequestID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DetailsInChangeRequest_SelectByChangeRequestID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DetailsInChangeRequest_SelectByChangeRequestID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DomainsInSite_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DomainsInSite_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DomainsInSite_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DomainsInSite_Insert
		(
			int SiteID,
			string DomainName,
			int DomainStatus,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DomainsInSite_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@DomainName", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, DomainName);
				AddParam(sqlCmd, "@DomainStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, DomainStatus);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DomainsInSite_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DomainsInSite_SelectActiveBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DomainsInSite_SelectActiveBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DomainsInSite_SelectActiveBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DomainsInSite_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DomainsInSite_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DomainsInSite_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DomainsInSite_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DomainsInSite_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DomainsInSite_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_DomainsInSite_SelectBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_DomainsInSite_SelectBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_DomainsInSite_SelectBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_DomainsInSite_UpdateByID
		(
			int ID,
			int SiteID,
			string DomainName,
			int DomainStatus
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_DomainsInSite_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@DomainName", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, DomainName);
				AddParam(sqlCmd, "@DomainStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, DomainStatus);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_DomainsInSite_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_dropdiagram
		(
			string diagramname,
			int owner_id
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_dropdiagram", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, diagramname);
				AddParam(sqlCmd, "@owner_id", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, owner_id);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_dropdiagram error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GeneralStatus_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GeneralStatus_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GeneralStatus_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMember_DeleteByID
		(
			int GroupID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMember_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMember_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMember_Insert
		(
			string GroupName,
			int CreatedBy,
			int GroupStatus,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMember_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupName", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, GroupName);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@GroupStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, GroupStatus);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMember_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMember_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMember_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMember_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMember_SelectByID
		(
			int GroupID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMember_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMember_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMember_UpdateByID
		(
			int GroupID,
			string GroupName,
			int GroupStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMember_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupID);
				AddParam(sqlCmd, "@GroupName", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, GroupName);
				AddParam(sqlCmd, "@GroupStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, GroupStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMember_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMemberInResourcePermission_DeleteByID
		(
			int GroupMemberID,
			int ResourceID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMemberInResourcePermission_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@ResourceID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ResourceID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMemberInResourcePermission_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMemberInResourcePermission_GetByID
		(
			int GroupMemberID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMemberInResourcePermission_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMemberInResourcePermission_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMemberInResourcePermission_Insert
		(
			int GroupMemberID,
			int ResourceID,
			int Create0,
			int Read0,
			int Update0,
			int Delete0,
			int Status,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMemberInResourcePermission_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@ResourceID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ResourceID);
				AddParam(sqlCmd, "@Create0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Create0);
				AddParam(sqlCmd, "@Read0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Read0);
				AddParam(sqlCmd, "@Update0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Update0);
				AddParam(sqlCmd, "@Delete0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Delete0);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMemberInResourcePermission_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMemberInResourcePermission_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMemberInResourcePermission_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMemberInResourcePermission_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_GroupMemberInResourcePermission_SelectByID
		(
			int GroupMemberID,
			int ResourceID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_GroupMemberInResourcePermission_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@ResourceID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ResourceID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_GroupMemberInResourcePermission_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_GroupMemberInResourcePermission_UpdateByID
		(
			int GroupMemberID,
			int ResourceID,
			int Create0,
			int Read0,
			int Update0,
			int Delete0,
			int Status,
			int ModifiedBy,
			int xGroupMemberID,
			int xResourceID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_GroupMemberInResourcePermission_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@ResourceID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ResourceID);
				AddParam(sqlCmd, "@Create0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Create0);
				AddParam(sqlCmd, "@Read0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Read0);
				AddParam(sqlCmd, "@Update0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Update0);
				AddParam(sqlCmd, "@Delete0", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Delete0);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				AddParam(sqlCmd, "@xGroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, xGroupMemberID);
				AddParam(sqlCmd, "@xResourceID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, xResourceID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_GroupMemberInResourcePermission_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_helpdiagramdefinition
		(
			string diagramname,
			int owner_id
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_helpdiagramdefinition", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, diagramname);
				AddParam(sqlCmd, "@owner_id", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, owner_id);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_helpdiagramdefinition error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_helpdiagrams
		(
			string diagramname,
			int owner_id
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_helpdiagrams", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, diagramname);
				AddParam(sqlCmd, "@owner_id", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, owner_id);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_helpdiagrams error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_HistoricalSRDetails_SelectByParentID
		(
			string ParentID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_HistoricalSRDetails_SelectByParentID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ParentID", SqlDbType.VarChar, 64, 32, 0, ParameterDirection.Input, ParentID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_HistoricalSRDetails_SelectByParentID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_HistoricalSRHeader_SelectByParentID
		(
			string ParentID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_HistoricalSRHeader_SelectByParentID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ParentID", SqlDbType.VarChar, 64, 32, 0, ParameterDirection.Input, ParentID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_HistoricalSRHeader_SelectByParentID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_HistoricalSRHeader_SelectBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_HistoricalSRHeader_SelectBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_HistoricalSRHeader_SelectBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_import
		(
			string S_No,
			string organisation_id,
			string organisation_fullname,
			string SiteID,
			string Costcentre,
			string User_Name,
			string Service_Type,
			string Monthly_OneTime,
			string Subscription_Start_Date,
			string Subscription_End_Date,
			string New_Existing_Terminated,
			string AssetID,
			string Hostname,
			string Remarks,
			ref int result,
			ref string errormsg
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_import", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@S_No", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, S_No);
				AddParam(sqlCmd, "@organisation_id", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, organisation_id);
				AddParam(sqlCmd, "@organisation_fullname", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, organisation_fullname);
				AddParam(sqlCmd, "@SiteID", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@Costcentre", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Costcentre);
				AddParam(sqlCmd, "@User_Name", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, User_Name);
				AddParam(sqlCmd, "@Service_Type", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Service_Type);
				AddParam(sqlCmd, "@Monthly_OneTime", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Monthly_OneTime);
				AddParam(sqlCmd, "@Subscription_Start_Date", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Subscription_Start_Date);
				AddParam(sqlCmd, "@Subscription_End_Date", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Subscription_End_Date);
				AddParam(sqlCmd, "@New_Existing_Terminated", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, New_Existing_Terminated);
				AddParam(sqlCmd, "@AssetID", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, AssetID);
				AddParam(sqlCmd, "@Hostname", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Hostname);
				AddParam(sqlCmd, "@Remarks", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Remarks);
				AddParam(sqlCmd, "@result", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				AddParam(sqlCmd, "@errormsg", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				result = get_int_value(sqlCmd.Parameters["@result"].Value);
				errormsg = get_string_value(sqlCmd.Parameters["@errormsg"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_import error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_IsRecordExists
		(
			string tablename,
			string fieldname,
			string value
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_IsRecordExists", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@tablename", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, tablename);
				AddParam(sqlCmd, "@fieldname", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, fieldname);
				AddParam(sqlCmd, "@value", SqlDbType.VarChar, 300, 150, 0, ParameterDirection.Input, value);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_IsRecordExists error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_KeyManagersInServiceForm_DeleteByID
		(
			int UserId
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_KeyManagersInServiceForm_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserId", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserId);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_KeyManagersInServiceForm_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_KeyManagersInServiceForm_GetByID
		(
			int UserId
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_KeyManagersInServiceForm_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserId", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserId);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_KeyManagersInServiceForm_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_KeyManagersInServiceForm_Insert
		(
			int ServiceFormID,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_KeyManagersInServiceForm_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ServiceFormID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ServiceFormID);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_KeyManagersInServiceForm_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_KeyManagersInServiceForm_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_KeyManagersInServiceForm_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_KeyManagersInServiceForm_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_KeyManagersInServiceForm_SelectByID
		(
			int UserId
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_KeyManagersInServiceForm_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserId", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserId);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_KeyManagersInServiceForm_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_KeyManagersInServiceForm_UpdateByID
		(
			int UserId,
			int ServiceFormID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_KeyManagersInServiceForm_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserId", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserId);
				AddParam(sqlCmd, "@ServiceFormID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ServiceFormID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_KeyManagersInServiceForm_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_MasterProfile_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_MasterProfile_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_MasterProfile_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_MasterProfile_Insert
		(
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_MasterProfile_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_MasterProfile_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_MasterProfile_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_MasterProfile_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_MasterProfile_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_MasterProfile_UpdateByID
		(
			int ID,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_MasterProfile_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_MasterProfile_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_Notice_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_Notice_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_Notice_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Notice_Insert
		(
			string Subject,
			string Body0,
			DateTime PublishDate,
			DateTime ExpiredDate,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Notice_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@Subject", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Subject);
				AddParam(sqlCmd, "@Body0", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Body0);
				AddParam(sqlCmd, "@PublishDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, PublishDate);
				AddParam(sqlCmd, "@ExpiredDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, ExpiredDate);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Notice_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Notice_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Notice_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Notice_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Notice_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Notice_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Notice_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Notice_SelectByNoExpired
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Notice_SelectByNoExpired", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Notice_SelectByNoExpired error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Notice_UpdateByID
		(
			int ID,
			string Subject,
			string Body0,
			DateTime PublishDate,
			DateTime ExpiredDate,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Notice_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@Subject", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, Subject);
				AddParam(sqlCmd, "@Body0", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Body0);
				AddParam(sqlCmd, "@PublishDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, PublishDate);
				AddParam(sqlCmd, "@ExpiredDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, ExpiredDate);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Notice_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_Delete
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_Delete", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_Delete error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_Insert
		(
			string OrgIDName,
			string OrgName,
			int IsMinistry,
			int OrgStatus,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@OrgIDName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, OrgIDName);
				AddParam(sqlCmd, "@OrgName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, OrgName);
				AddParam(sqlCmd, "@IsMinistry", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsMinistry);
				AddParam(sqlCmd, "@OrgStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, OrgStatus);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_Organization_SelectActiveByID_BasedOnMinistry
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_Organization_SelectActiveByID_BasedOnMinistry", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_Organization_SelectActiveByID_BasedOnMinistry error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_SelectAllActive
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_SelectAllActive", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_SelectAllActive error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_Organization_SelectByID_BasedOnMinistry
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_Organization_SelectByID_BasedOnMinistry", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_Organization_SelectByID_BasedOnMinistry error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Organization_UpdateByID
		(
			int ID,
			string OrgIDName,
			string OrgName,
			int IsMinistry,
			int OrgStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Organization_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@OrgIDName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, OrgIDName);
				AddParam(sqlCmd, "@OrgName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, OrgName);
				AddParam(sqlCmd, "@IsMinistry", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsMinistry);
				AddParam(sqlCmd, "@OrgStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, OrgStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Organization_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_ReasonsInChangeRequest_DeleteByChangeRequestID
		(
			int ChangeRequestID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_ReasonsInChangeRequest_DeleteByChangeRequestID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_ReasonsInChangeRequest_DeleteByChangeRequestID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_ReasonsInChangeRequest_Insert
		(
			int ChangeRequestID,
			int ChangeRequestReasonID,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_ReasonsInChangeRequest_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				AddParam(sqlCmd, "@ChangeRequestReasonID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestReasonID);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_ReasonsInChangeRequest_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_ReasonsInChangeRequest_SelectByChangeRequestID
		(
			int ChangeRequestID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_ReasonsInChangeRequest_SelectByChangeRequestID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ChangeRequestID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ChangeRequestID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_ReasonsInChangeRequest_SelectByChangeRequestID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_renamediagram
		(
			string diagramname,
			int owner_id,
			string new_diagramname
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_renamediagram", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, diagramname);
				AddParam(sqlCmd, "@owner_id", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, owner_id);
				AddParam(sqlCmd, "@new_diagramname", SqlDbType.VarChar, 256, 128, 0, ParameterDirection.Input, new_diagramname);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_renamediagram error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_GetByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_Insert
		(
			int Parent,
			string ResourceName,
			string PageURL,
			int PageOrder,
			int Status,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@Parent", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, Parent);
				AddParam(sqlCmd, "@ResourceName", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, ResourceName);
				AddParam(sqlCmd, "@PageURL", SqlDbType.VarChar, 300, 150, 0, ParameterDirection.Input, PageURL);
				AddParam(sqlCmd, "@PageOrder", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, PageOrder);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_SelectByStructure
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_SelectByStructure", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_SelectByStructure error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_SelectByStructureWithGroupMemberID
		(
			int GroupMemberID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_SelectByStructureWithGroupMemberID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_SelectByStructureWithGroupMemberID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_ResourceMenu_UpdateByID
		(
			int ID,
			int Parent,
			string ResourceName,
			string PageURL,
			int PageOrder,
			int Status,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_ResourceMenu_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@Parent", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, Parent);
				AddParam(sqlCmd, "@ResourceName", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, ResourceName);
				AddParam(sqlCmd, "@PageURL", SqlDbType.VarChar, 300, 150, 0, ParameterDirection.Input, PageURL);
				AddParam(sqlCmd, "@PageOrder", SqlDbType.Int, 4, 10, 0, ParameterDirection.Input, PageOrder);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_ResourceMenu_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Role_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Role_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Role_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Role_GetByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Role_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Role_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Role_Insert
		(
			string RoleName,
			int Status,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Role_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@RoleName", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, RoleName);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Role_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Role_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Role_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Role_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Role_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Role_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Role_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Role_UpdateByID
		(
			int ID,
			string RoleName,
			int Status,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Role_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@RoleName", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, RoleName);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Role_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SelectSubmittedEffCostCentreTransferSR
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SelectSubmittedEffCostCentreTransferSR", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SelectSubmittedEffCostCentreTransferSR error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_GetByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_Insert
		(
			int OrgID,
			string SiteIDName,
			string SiteName,
			int SiteStatus,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				AddParam(sqlCmd, "@SiteIDName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, SiteIDName);
				AddParam(sqlCmd, "@SiteName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, SiteName);
				AddParam(sqlCmd, "@SiteStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, SiteStatus);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_SelectActiveByOrgID
		(
			int OrgID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_SelectActiveByOrgID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_SelectActiveByOrgID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_SelectByOrgID
		(
			int OrgID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_SelectByOrgID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_SelectByOrgID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_SitesInOrganization_UpdateByID
		(
			int ID,
			int OrgID,
			string SiteIDName,
			string SiteName,
			int SiteStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_SitesInOrganization_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				AddParam(sqlCmd, "@SiteIDName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, SiteIDName);
				AddParam(sqlCmd, "@SiteName", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, SiteName);
				AddParam(sqlCmd, "@SiteStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, SiteStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_SitesInOrganization_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_GetByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_Insert
		(
			int ServiceFormID,
			int MasterProfileID,
			int CreatedBy,
			int Status,
			DateTime EffectiveDate,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ServiceFormID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ServiceFormID);
				AddParam(sqlCmd, "@MasterProfileID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, MasterProfileID);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@EffectiveDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, EffectiveDate);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_SelectAllByCostCentre
		(
			int CostCentreID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_SelectAllByCostCentre", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_SelectAllByCostCentre error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_SelectAllByOrg
		(
			int OrgID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_SelectAllByOrg", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_SelectAllByOrg error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool SP_Subscriber_SelectByAssetID
		(
			string AssetID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("SP_Subscriber_SelectByAssetID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@AssetID", SqlDbType.VarChar, 100, 50, 0, ParameterDirection.Input, AssetID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "SP_Subscriber_SelectByAssetID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_SelectBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_SelectBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_SelectBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_UpdateByID
		(
			int ID,
			int MasterProfileID,
			int ModifiedBy,
			int Status,
			string NRICName,
			string Email
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@MasterProfileID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, MasterProfileID);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				AddParam(sqlCmd, "@NRICName", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, NRICName);
				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Subscriber_UpdateByTermination
		(
			int ID,
			DateTime TerminatedDate,
			int TerminatedBy,
			int Status
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Subscriber_UpdateByTermination", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@TerminatedDate", SqlDbType.DateTime, 8, 23, 3, ParameterDirection.Input, TerminatedDate);
				AddParam(sqlCmd, "@TerminatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TerminatedBy);
				AddParam(sqlCmd, "@Status", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, Status);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Subscriber_UpdateByTermination error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Template_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Template_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Template_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Template_Insert
		(
			int TemplateType,
			string TemplateName,
			string EmailTo,
			string EmailCc,
			string EmailBcc,
			int IsEmailToDestKM,
			string Subject0,
			int IsAttachTabFile,
			int IsAttachKMTextFile,
			string Body0,
			string Footer0,
			int IsDetailStatusChange,
			int TemplateStatus,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Template_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateType);
				AddParam(sqlCmd, "@TemplateName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, TemplateName);
				AddParam(sqlCmd, "@EmailTo", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, EmailTo);
				AddParam(sqlCmd, "@EmailCc", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, EmailCc);
				AddParam(sqlCmd, "@EmailBcc", SqlDbType.VarChar, 1020, 510, 0, ParameterDirection.Input, EmailBcc);
				AddParam(sqlCmd, "@IsEmailToDestKM", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsEmailToDestKM);
				AddParam(sqlCmd, "@Subject0", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, Subject0);
				AddParam(sqlCmd, "@IsAttachTabFile", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsAttachTabFile);
				AddParam(sqlCmd, "@IsAttachKMTextFile", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsAttachKMTextFile);
				AddParam(sqlCmd, "@Body0", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Body0);
				AddParam(sqlCmd, "@Footer0", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Footer0);
				AddParam(sqlCmd, "@IsDetailStatusChange", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsDetailStatusChange);
				AddParam(sqlCmd, "@TemplateStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, TemplateStatus);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Template_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Template_SelectActiveByTemplateType
		(
			int TemplateType,
			int IsDetailStatusChange,
			int RequestStatus,
			int RequestType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Template_SelectActiveByTemplateType", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateType);
				AddParam(sqlCmd, "@IsDetailStatusChange", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsDetailStatusChange);
				AddParam(sqlCmd, "@RequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RequestStatus);
				AddParam(sqlCmd, "@RequestType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RequestType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Template_SelectActiveByTemplateType error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Template_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Template_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Template_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Template_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Template_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Template_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_Template_UpdateByID
		(
			int ID,
			int TemplateType,
			string TemplateName,
			string EmailTo,
			string EmailCc,
			string EmailBcc,
			int IsEmailToDestKM,
			string Subject0,
			int IsAttachTabFile,
			int IsAttachKMTextFile,
			string Body0,
			string Footer0,
			int IsDetailStatusChange,
			int TemplateStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_Template_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@TemplateType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateType);
				AddParam(sqlCmd, "@TemplateName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, TemplateName);
				AddParam(sqlCmd, "@EmailTo", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, EmailTo);
				AddParam(sqlCmd, "@EmailCc", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, EmailCc);
				AddParam(sqlCmd, "@EmailBcc", SqlDbType.VarChar, 1020, 510, 0, ParameterDirection.Input, EmailBcc);
				AddParam(sqlCmd, "@IsEmailToDestKM", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsEmailToDestKM);
				AddParam(sqlCmd, "@Subject0", SqlDbType.VarChar, 510, 255, 0, ParameterDirection.Input, Subject0);
				AddParam(sqlCmd, "@IsAttachTabFile", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsAttachTabFile);
				AddParam(sqlCmd, "@IsAttachKMTextFile", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsAttachKMTextFile);
				AddParam(sqlCmd, "@Body0", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Body0);
				AddParam(sqlCmd, "@Footer0", SqlDbType.VarChar, 16, 0, 0, ParameterDirection.Input, Footer0);
				AddParam(sqlCmd, "@IsDetailStatusChange", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, IsDetailStatusChange);
				AddParam(sqlCmd, "@TemplateStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, TemplateStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_Template_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateBodyDetails_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateBodyDetails_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateBodyDetails_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateBodyDetails_DeleteByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateBodyDetails_DeleteByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateBodyDetails_DeleteByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateBodyDetails_Insert
		(
			int TemplateID,
			string ColumnName,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateBodyDetails_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@ColumnName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, ColumnName);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateBodyDetails_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateBodyDetails_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateBodyDetails_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateBodyDetails_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateBodyDetails_SelectByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateBodyDetails_SelectByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateBodyDetails_SelectByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateBodyDetails_UpdateByID
		(
			int ID,
			int TemplateID,
			string ColumnName
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateBodyDetails_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@ColumnName", SqlDbType.VarChar, 200, 100, 0, ParameterDirection.Input, ColumnName);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateBodyDetails_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateColumnMapping_SelectByTemplateType
		(
			int TemplateType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateColumnMapping_SelectByTemplateType", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateColumnMapping_SelectByTemplateType error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRecipientGroup_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRecipientGroup_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRecipientGroup_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRecipientGroup_DeleteByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRecipientGroup_DeleteByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRecipientGroup_DeleteByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRecipientGroup_Insert
		(
			int TemplateID,
			string SendToType,
			int GroupMemberID,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRecipientGroup_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@SendToType", SqlDbType.VarChar, 10, 5, 0, ParameterDirection.Input, SendToType);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRecipientGroup_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRecipientGroup_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRecipientGroup_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRecipientGroup_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRecipientGroup_SelectByTemplateIDSendToType
		(
			int TemplateID,
			string SendToType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRecipientGroup_SelectByTemplateIDSendToType", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@SendToType", SqlDbType.VarChar, 10, 5, 0, ParameterDirection.Input, SendToType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRecipientGroup_SelectByTemplateIDSendToType error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRecipientGroup_UpdateByID
		(
			int ID,
			int TemplateID,
			string SendToType,
			int GroupMemberID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRecipientGroup_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@SendToType", SqlDbType.VarChar, 10, 5, 0, ParameterDirection.Input, SendToType);
				AddParam(sqlCmd, "@GroupMemberID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupMemberID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRecipientGroup_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestStatus_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestStatus_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestStatus_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestStatus_DeleteByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestStatus_DeleteByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestStatus_DeleteByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestStatus_Insert
		(
			int TemplateID,
			int RequestStatus,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestStatus_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@RequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RequestStatus);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestStatus_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestStatus_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestStatus_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestStatus_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestStatus_SelectByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestStatus_SelectByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestStatus_SelectByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestStatus_UpdateByID
		(
			int ID,
			int TemplateID,
			int RequestStatus
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestStatus_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@RequestStatus", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RequestStatus);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestStatus_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestType_DeleteByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestType_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestType_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestType_DeleteByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestType_DeleteByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestType_DeleteByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestType_Insert
		(
			int TemplateID,
			int RequestType,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestType_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@RequestType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RequestType);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestType_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestType_SelectByID
		(
			int ID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestType_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestType_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestType_SelectByTemplateID
		(
			int TemplateID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestType_SelectByTemplateID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestType_SelectByTemplateID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_TemplateRequestType_UpdateByID
		(
			int ID,
			int TemplateID,
			int RequestType
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_TemplateRequestType_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@ID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ID);
				AddParam(sqlCmd, "@TemplateID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, TemplateID);
				AddParam(sqlCmd, "@RequestType", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RequestType);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_TemplateRequestType_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool sp_upgraddiagrams
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("sp_upgraddiagrams", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "sp_upgraddiagrams error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_DeleteByID
		(
			int UserID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_DoLogin
		(
			string LoginID,
			string LoginPassword
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_DoLogin", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@LoginID", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginID);
				AddParam(sqlCmd, "@LoginPassword", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginPassword);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_DoLogin error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_GetByID
		(
			int UserID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_Insert
		(
			string LoginId,
			string LoginPassword,
			string NRIC,
			string Name0,
			string Address01,
			string Address02,
			string PostCode,
			string PrimaryPhone,
			string SecondaryPhone,
			string FaxNumber,
			string Email,
			int UserTypeID,
			int OrgID,
			int SiteID,
			int CostCentreID,
			int UserStatus,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@LoginId", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginId);
				AddParam(sqlCmd, "@LoginPassword", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, LoginPassword);
				AddParam(sqlCmd, "@NRIC", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, NRIC);
				AddParam(sqlCmd, "@Name0", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Name0);
				AddParam(sqlCmd, "@Address01", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Address01);
				AddParam(sqlCmd, "@Address02", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Address02);
				AddParam(sqlCmd, "@PostCode", SqlDbType.VarChar, 10, 10, 0, ParameterDirection.Input, PostCode);
				AddParam(sqlCmd, "@PrimaryPhone", SqlDbType.VarChar, 15, 15, 0, ParameterDirection.Input, PrimaryPhone);
				AddParam(sqlCmd, "@SecondaryPhone", SqlDbType.VarChar, 15, 15, 0, ParameterDirection.Input, SecondaryPhone);
				AddParam(sqlCmd, "@FaxNumber", SqlDbType.VarChar, 15, 15, 0, ParameterDirection.Input, FaxNumber);
				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				AddParam(sqlCmd, "@UserTypeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserTypeID);
				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				AddParam(sqlCmd, "@UserStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, UserStatus);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 4, 10, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectActiveByGroupIDSiteID
		(
			int GroupID,
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectActiveByGroupIDSiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@GroupID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, GroupID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectActiveByGroupIDSiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectActiveKM
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectActiveKM", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectActiveKM error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectAllKM
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectAllKM", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectAllKM error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectAllKMBySiteID
		(
			int SiteID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectAllKMBySiteID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectAllKMBySiteID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectBookingAdmin
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectBookingAdmin", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectBookingAdmin error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectByEmail
		(
			string Email
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectByEmail", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectByEmail error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectByID
		(
			int UserID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_SelectByLoginID
		(
			string LoginID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_SelectByLoginID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@LoginID", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_SelectByLoginID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_UpdateByID
		(
			int UserID,
			string LoginId,
			string LoginPassword,
			string NRIC,
			string Name0,
			string Address01,
			string Address02,
			string PostCode,
			string PrimaryPhone,
			string SecondaryPhone,
			string FaxNumber,
			string Email,
			int UserTypeID,
			int OrgID,
			int SiteID,
			int CostCentreID,
			int UserStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@LoginId", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginId);
				AddParam(sqlCmd, "@LoginPassword", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, LoginPassword);
				AddParam(sqlCmd, "@NRIC", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, NRIC);
				AddParam(sqlCmd, "@Name0", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Name0);
				AddParam(sqlCmd, "@Address01", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Address01);
				AddParam(sqlCmd, "@Address02", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, Address02);
				AddParam(sqlCmd, "@PostCode", SqlDbType.VarChar, 10, 10, 0, ParameterDirection.Input, PostCode);
				AddParam(sqlCmd, "@PrimaryPhone", SqlDbType.VarChar, 15, 15, 0, ParameterDirection.Input, PrimaryPhone);
				AddParam(sqlCmd, "@SecondaryPhone", SqlDbType.VarChar, 15, 15, 0, ParameterDirection.Input, SecondaryPhone);
				AddParam(sqlCmd, "@FaxNumber", SqlDbType.VarChar, 15, 15, 0, ParameterDirection.Input, FaxNumber);
				AddParam(sqlCmd, "@Email", SqlDbType.VarChar, 200, 200, 0, ParameterDirection.Input, Email);
				AddParam(sqlCmd, "@UserTypeID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserTypeID);
				AddParam(sqlCmd, "@OrgID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, OrgID);
				AddParam(sqlCmd, "@SiteID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, SiteID);
				AddParam(sqlCmd, "@CostCentreID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CostCentreID);
				AddParam(sqlCmd, "@UserStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, UserStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_UpdateByLoginIDForPassword
		(
			string LoginID,
			string LoginPassword
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_UpdateByLoginIDForPassword", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@LoginID", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginID);
				AddParam(sqlCmd, "@LoginPassword", SqlDbType.VarChar, 400, 200, 0, ParameterDirection.Input, LoginPassword);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_UpdateByLoginIDForPassword error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UserProfile_UpdateUserStatusByUserID
		(
			int UserID,
			int UserStatus,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UserProfile_UpdateUserStatusByUserID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@UserStatus", SqlDbType.Int, 1, 1, 0, ParameterDirection.Input, UserStatus);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UserProfile_UpdateUserStatusByUserID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UsersInRole_DeleteByID
		(
			int UserID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UsersInRole_DeleteByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UsersInRole_DeleteByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UsersInRole_GetByID
		(
			int UserID,
			int RoleID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UsersInRole_GetByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@RoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RoleID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UsersInRole_GetByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UsersInRole_Insert
		(
			int RoleID,
			int UserID,
			int CreatedBy,
			ref int xPrimaryKey
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UsersInRole_Insert", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@RoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RoleID);
				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@CreatedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, CreatedBy);
				AddParam(sqlCmd, "@xPrimaryKey", SqlDbType.Int, 8, 19, 0, ParameterDirection.Output, null);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				xPrimaryKey = get_int_value(sqlCmd.Parameters["@xPrimaryKey"].Value);
				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UsersInRole_Insert error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UsersInRole_SelectAll
		(
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UsersInRole_SelectAll", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UsersInRole_SelectAll error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UsersInRole_SelectByID
		(
			int UserID,
			int RoleID
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UsersInRole_SelectByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@RoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RoleID);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UsersInRole_SelectByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
		public bool Sp_UsersInRole_UpdateByID
		(
			int UserID,
			int RoleID,
			int ModifiedBy
		)
		{
			SqlConnection conn = null;
			SqlTransaction tran = null;
			SqlCommand sqlCmd = null;
			try
			{
				conn = this.GetConnection();
				if (conn == null) return false;
				tran = this.GetTransaction();

				sqlCmd = new SqlCommand("Sp_UsersInRole_UpdateByID", conn);
				sqlCmd.CommandTimeout = this.ExecuteTimeout;
				sqlCmd.CommandType = CommandType.StoredProcedure;
				if (tran != null) sqlCmd.Transaction = tran;

				AddParam(sqlCmd, "@UserID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, UserID);
				AddParam(sqlCmd, "@RoleID", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, RoleID);
				AddParam(sqlCmd, "@ModifiedBy", SqlDbType.Int, 8, 19, 0, ParameterDirection.Input, ModifiedBy);
				sqlCmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int, 4);
				sqlCmd.Parameters["@RETURN_VALUE"].Direction = ParameterDirection.ReturnValue;
				sqlCmd.ExecuteNonQuery();

				int _temp = Convert.ToInt32(sqlCmd.Parameters["@RETURN_VALUE"].Value.ToString());
				return true;
			}
			catch (Exception ex)
			{
				this.LastErrorCode = -1;
				this.LastError = "Sp_UsersInRole_UpdateByID error.\r\n" + ex.ExceptionInfo();
				return false;
			}
			finally
			{
				if (sqlCmd != null) sqlCmd.Dispose();
				if (conn != null && !this.InTransaction)
				{
					conn.Close();
					conn.Dispose();
				}
			}
		}
	}
}